From 55b3416ae0d8d530c3296f0c8a9434e0631cf089 Mon Sep 17 00:00:00 2001 From: Narendra Vijayarao Date: Mon, 16 Apr 2018 14:03:14 +0100 Subject: [PATCH] MTDSA-1469 Add VRN_NOT_FOUND error to View VAT Returns --- app/uk/gov/hmrc/vatapi/models/des/DesError.scala | 3 ++- .../vatapi/resources/wrappers/VatReturnResponse.scala | 3 ++- .../vatapi/resources/ValueAddedTaxReturnsSpec.scala | 11 +++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/uk/gov/hmrc/vatapi/models/des/DesError.scala b/app/uk/gov/hmrc/vatapi/models/des/DesError.scala index d2b8fe9b..aa11ef25 100644 --- a/app/uk/gov/hmrc/vatapi/models/des/DesError.scala +++ b/app/uk/gov/hmrc/vatapi/models/des/DesError.scala @@ -41,7 +41,8 @@ object DesErrorCode extends Enumeration { INVALID_IDNUMBER, INVALID_DATETO, INVALID_DATEFROM, - NOT_FOUND + NOT_FOUND, + VRN_NOT_FOUND = Value implicit val format: Format[DesErrorCode] = EnumJson.enumFormat(DesErrorCode, diff --git a/app/uk/gov/hmrc/vatapi/resources/wrappers/VatReturnResponse.scala b/app/uk/gov/hmrc/vatapi/resources/wrappers/VatReturnResponse.scala index ffb41691..01fd9b94 100644 --- a/app/uk/gov/hmrc/vatapi/resources/wrappers/VatReturnResponse.scala +++ b/app/uk/gov/hmrc/vatapi/resources/wrappers/VatReturnResponse.scala @@ -22,7 +22,7 @@ import play.api.mvc.Result import play.api.mvc.Results.{BadRequest, InternalServerError} import uk.gov.hmrc.http.HttpResponse import uk.gov.hmrc.vatapi.httpparsers.NRSData -import uk.gov.hmrc.vatapi.models.des.DesErrorCode.{DATE_RANGE_TOO_LARGE, DUPLICATE_SUBMISSION, INVALID_ARN, INVALID_PAYLOAD, INVALID_PERIODKEY, INVALID_VRN} +import uk.gov.hmrc.vatapi.models.des.DesErrorCode._ import uk.gov.hmrc.vatapi.models.{DesTransformError, DesTransformValidator, Errors, VatReturn, des} import uk.gov.hmrc.vatapi.resources.VatReturnsResource.Forbidden @@ -51,6 +51,7 @@ case class VatReturnResponse(underlying: HttpResponse) extends Response { case 400 if errorCodeIsOneOf(INVALID_PERIODKEY) => BadRequest(toJson(Errors.InvalidPeriodKey)) case 400 if errorCodeIsOneOf(DUPLICATE_SUBMISSION) => Forbidden(toJson(Errors.businessError(Errors.DuplicateVatSubmission))) case 403 if errorCodeIsOneOf(DATE_RANGE_TOO_LARGE) => Forbidden(toJson(Errors.businessError(Errors.DateRangeTooLarge))) + case 403 if errorCodeIsOneOf(VRN_NOT_FOUND) => InternalServerError(toJson(Errors.InternalServerError)) } } diff --git a/func/uk/gov/hmrc/vatapi/resources/ValueAddedTaxReturnsSpec.scala b/func/uk/gov/hmrc/vatapi/resources/ValueAddedTaxReturnsSpec.scala index 92c235ce..31d20044 100644 --- a/func/uk/gov/hmrc/vatapi/resources/ValueAddedTaxReturnsSpec.scala +++ b/func/uk/gov/hmrc/vatapi/resources/ValueAddedTaxReturnsSpec.scala @@ -229,6 +229,17 @@ class ValueAddedTaxReturnsSpec extends BaseFunctionalSpec { .bodyHasPath("\\errors(0)\\code", "DATE_RANGE_TOO_LARGE") } + "return internal server error (500) if the vat returns with DES vrn not found error" in { + given() + .userIsFullyAuthorisedForTheResource + .des().vatReturns.expectVatReturnRetrieveToFail(vrn, "VRN_NOT_FOUND") + .when() + .get(s"/$vrn/returns/0001") + .thenAssertThat() + .statusIs(500) + .bodyHasPath("\\code", "INTERNAL_SERVER_ERROR") + } + "return bad request (400) if the periodKey is invalid" in { given() .userIsFullyAuthorisedForTheResource