Skip to content

Commit

Permalink
Merge pull request #121 from hmrc/MTDSA-1432
Browse files Browse the repository at this point in the history
MTDSA-1432 Improve logging for VAT API
  • Loading branch information
jonathanleather authored Apr 18, 2018
2 parents 58032ce + 54024a6 commit d28753c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/uk/gov/hmrc/vatapi/resources/ObligationsResource.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object ObligationsResource extends BaseResource {
private val connector = ObligationsConnector

def retrieveObligations(vrn: Vrn, params: ObligationsQueryParams): Action[AnyContent] = APIAction(vrn).async { implicit request =>
logger.debug(s"[ObligationsResource][retrieveObligations] - Get Obligations")
logger.debug(s"[ObligationsResource][retrieveObligations] - Retrieve Obligations for vrn : $vrn")
fromDes {
for {
response <- execute { _ => connector.get(vrn, params) }
Expand All @@ -48,7 +48,7 @@ object ObligationsResource extends BaseResource {
response.obligations(vrn) match {
case Right(obj) => obj.map(x => Ok(Json.toJson(x))).getOrElse(NotFound)
case Left(ex) =>
logger.error(ex.msg)
logger.error(s"[ObligationsResource][retrieveObligations] Json format from DES doesn't match the Obligations model: ${ex.msg}")
InternalServerError(Json.toJson(Errors.InternalServerError))
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/uk/gov/hmrc/vatapi/resources/VatReturnsResource.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ object VatReturnsResource extends BaseResource {
case 200 => response.vatReturnOrError match {
case Right(vatReturn) => Ok(Json.toJson(vatReturn))
case Left(error) =>
logger.error(error.msg)
logger.error(s"[VatReturnsResource] [retrieveVatReturns] Json format from DES doesn't match the VatReturn model: ${error.msg}")
InternalServerError
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,32 @@ case class FinancialDataResponse(underlying: HttpResponse) extends Response {
def getLiabilities(vrn: Vrn): Either[DesTransformError, Liabilities] = {

def deserialise(js: JsValue) = js.validate[des.FinancialData] match {
case JsError(errors) => Left(ParseError(s"Unable to parse the response from DES as Json: $errors"))
case JsError(errors) => Left(ParseError(s"[FinancialDataResponse][getLiabilities - deserialise] Json format from DES doesn't match the FinancialData model: $errors"))
case JsSuccess(financialData, _) =>
DesTransformValidator[des.FinancialData, Liabilities].from(financialData)
}
jsonOrError match {
case Right(js) => deserialise(js)
case Left(e) => Left(ParseError(s"Unable to parse the response from DES as Json: $e"))
case Right(js) =>
logger.info(s"[FinancialDataResponse][getLiabilities - jsonOrError] Json response body from DES : ${js}")
deserialise(js)
case Left(e) =>
logger.error(s"[FinancialDataResponse][getLiabilities - jsonOrError] Non json response from DES : ${underlying.body}")
Left(ParseError(s"Unable to parse the response from DES as Json: $e"))
}
}

def getPayments(vrn: Vrn): Either[DesTransformError, Payments] = {
def deserialise(js: JsValue) = js.validate[des.FinancialData] match {
case JsError(errors) => Left(ParseError(s"Unable to parse the response from DES as Json: $errors"))
case JsError(errors) => Left(ParseError(s"[FinancialDataResponse][getPayments - deserialise] Json format from DES doesn't match the FinancialData model: $errors"))
case JsSuccess(financialData, _) => DesTransformValidator[des.FinancialData, Payments].from(financialData)
}
jsonOrError match {
case Right(js) => deserialise(js)
case Left(e) => Left(ParseError(s"Unable to parse the response from DES as Json: $e"))
case Right(js) =>
logger.info(s"[FinancialDataResponse][getPayments - jsonOrError] Json response body from DES : ${js}")
deserialise(js)
case Left(e) =>
logger.error(s"[FinancialDataResponse][getPayments - jsonOrError] Non json response from DES : ${underlying.body}")
Left(ParseError(s"Unable to parse the response from DES as Json: $e"))
}
}

Expand Down

0 comments on commit d28753c

Please sign in to comment.