From 7d4d8e8310946f4b9d3c8f91e123ee5fe0292e48 Mon Sep 17 00:00:00 2001 From: Narendra Vijayarao Date: Wed, 18 Apr 2018 15:27:48 +0100 Subject: [PATCH 1/2] MTDSA-1432 Improve logging for VAT API --- .../hmrc/vatapi/resources/ObligationsResource.scala | 4 ++-- .../gov/hmrc/vatapi/resources/VatReturnsResource.scala | 2 +- .../resources/wrappers/FinancialDataResponse.scala | 10 +++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/uk/gov/hmrc/vatapi/resources/ObligationsResource.scala b/app/uk/gov/hmrc/vatapi/resources/ObligationsResource.scala index b11fa6af..60e0d17d 100644 --- a/app/uk/gov/hmrc/vatapi/resources/ObligationsResource.scala +++ b/app/uk/gov/hmrc/vatapi/resources/ObligationsResource.scala @@ -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) } @@ -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)) } } diff --git a/app/uk/gov/hmrc/vatapi/resources/VatReturnsResource.scala b/app/uk/gov/hmrc/vatapi/resources/VatReturnsResource.scala index 0a642f88..f6beb12d 100644 --- a/app/uk/gov/hmrc/vatapi/resources/VatReturnsResource.scala +++ b/app/uk/gov/hmrc/vatapi/resources/VatReturnsResource.scala @@ -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 } } diff --git a/app/uk/gov/hmrc/vatapi/resources/wrappers/FinancialDataResponse.scala b/app/uk/gov/hmrc/vatapi/resources/wrappers/FinancialDataResponse.scala index 22963994..949020b8 100644 --- a/app/uk/gov/hmrc/vatapi/resources/wrappers/FinancialDataResponse.scala +++ b/app/uk/gov/hmrc/vatapi/resources/wrappers/FinancialDataResponse.scala @@ -42,12 +42,16 @@ case class FinancialDataResponse(underlying: HttpResponse) extends Response { 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")) } } From 54024a6b3c7936c79e17e43ab21ec613a96fe5d6 Mon Sep 17 00:00:00 2001 From: Narendra Vijayarao Date: Wed, 18 Apr 2018 15:59:39 +0100 Subject: [PATCH 2/2] MTDSA-1432 Improve logging for VAT API --- .../resources/wrappers/FinancialDataResponse.scala | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/uk/gov/hmrc/vatapi/resources/wrappers/FinancialDataResponse.scala b/app/uk/gov/hmrc/vatapi/resources/wrappers/FinancialDataResponse.scala index 949020b8..fe851392 100644 --- a/app/uk/gov/hmrc/vatapi/resources/wrappers/FinancialDataResponse.scala +++ b/app/uk/gov/hmrc/vatapi/resources/wrappers/FinancialDataResponse.scala @@ -30,13 +30,17 @@ 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")) } }