Skip to content

Commit 3f6df73

Browse files
authored
[DL-17097] Remove IF gateway error validation (#1058)
1 parent b95be59 commit 3f6df73

File tree

8 files changed

+84
-691
lines changed

8 files changed

+84
-691
lines changed

app/v1/connectors/httpparsers/FinancialDataHttpParser.scala

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
package v1.connectors.httpparsers
1818

1919
import play.api.http.Status._
20-
import play.api.libs.json.{ JsError, JsSuccess, JsValue, Json }
20+
import play.api.libs.json.{ JsError, JsSuccess, JsValue }
2121
import uk.gov.hmrc.http.{ HttpReads, HttpResponse }
2222
import utils.Logging
2323
import v1.connectors.Outcome
2424
import v1.models.errors._
2525
import v1.models.outcomes.ResponseWrapper
26-
import v1.models.response.financialData.{ FinancialDataErrorsHIP, FinancialDataErrorsIF, FinancialDataResponse }
26+
import v1.models.response.financialData.{ FinancialDataErrorsHIP, FinancialDataResponse }
2727

2828
object FinancialDataHttpParser extends Logging {
2929

@@ -47,63 +47,11 @@ object FinancialDataHttpParser extends Logging {
4747
}
4848

4949
def errorHelper(jsonString: JsValue): MtdError = {
50-
val financialDataErrorsIF = jsonString.validate[FinancialDataErrorsIF]
51-
val financialDataErrorsHIP = jsonString.validate[FinancialDataErrorsHIP]
52-
53-
(financialDataErrorsIF, financialDataErrorsHIP) match {
54-
case (JsSuccess(errorsIF, _), _) => convertToMtdErrorsIF(errorsIF)
55-
case (_, JsSuccess(errorsHIP, _)) => convertToMtdErrorsHIP(errorsHIP)
56-
case _ =>
57-
MtdError("SERVER_ERROR", "Unable to validate json error response", Some(jsonString))
58-
}
59-
}
60-
61-
private def convertToMtdErrorsIF(errorsIF: FinancialDataErrorsIF): MtdError = {
62-
val convertedErrors = errorsIF.failures.map { error =>
63-
error.code match {
64-
case "INVALID_IDNUMBER" => FinancialInvalidIdNumber
65-
case "INVALID_SEARCH_ITEM" => FinancialInvalidSearchItem
66-
case "NO_DATA_FOUND" => FinancialNotDataFound
67-
case "INVALID_CORRELATIONID" => DownstreamError
68-
case "INVALID_IDTYPE" => DownstreamError
69-
case "INVALID_REGIME_TYPE" => DownstreamError
70-
case "INVALID_SEARCH_TYPE" => DownstreamError
71-
case "INVALID_DATE_FROM" => DownstreamError
72-
case "INVALID_DATE_TO" => DownstreamError
73-
case "INVALID_DATE_TYPE" => DownstreamError
74-
case "INVALID_INCLUDE_CLEARED_ITEMS" => DownstreamError
75-
case "INVALID_INCLUDE_STATISTICAL_ITEMS" => DownstreamError
76-
case "INVALID_INCLUDE_PAYMENT_ON_ACCOUNT" => DownstreamError
77-
case "INVALID_ADD_REGIME_TOTALISATION" => DownstreamError
78-
case "INVALID_ADD_LOCK_INFORMATION" => DownstreamError
79-
case "INVALID_ADD_PENALTY_DETAILS" => DownstreamError
80-
case "INVALID_ADD_POSTED_INTEREST_DETAILS" => DownstreamError
81-
case "INVALID_ADD_ACCRUING_INTEREST_DETAILS" => DownstreamError
82-
case "INVALID_REQUEST" => DownstreamError
83-
case "INVALID_TARGETED_SEARCH" => DownstreamError
84-
case "INVALID_SELECTION_CRITERIA" => DownstreamError
85-
case "INVALID_DATA_ENRICHMENT" => DownstreamError
86-
case "DUPLICATE_SUBMISSION" => DownstreamError
87-
case "INVALID_ID" => DownstreamError
88-
case "INVALID_DOC_NUMBER_OR_CHARGE_REFERENCE_NUMBER" => FinancialInvalidSearchItem
89-
case "REQUEST_NOT_PROCESSED" => DownstreamError
90-
case "INVALID_DATA_TYPE" => DownstreamError
91-
case "INVALID_DATE_RANGE" => DownstreamError
92-
case "SERVER_ERROR" => DownstreamError
93-
case "SERVICE_UNAVAILABLE" => DownstreamError
94-
case _ => MtdError(error.code, error.reason)
95-
}
96-
}
97-
98-
val head = convertedErrors.head
99-
val error = if (convertedErrors.tail.isEmpty) {
100-
head
101-
} else if (convertedErrors.contains(DownstreamError)) {
102-
DownstreamError
103-
} else {
104-
MtdError("INVALID_REQUEST", "Invalid request financial details", Some(Json.toJson(convertedErrors)))
50+
jsonString.validate[FinancialDataErrorsHIP] match {
51+
case JsSuccess(errorsHIP, _) => convertToMtdErrorsHIP(errorsHIP)
52+
case JsError(errors) =>
53+
MtdError("SERVER_ERROR", s"Unable to validate json error response with errors: $errors", Some(jsonString))
10554
}
106-
error
10755
}
10856

10957
private def convertToMtdErrorsHIP(errorsHIP: FinancialDataErrorsHIP): MtdError = {

app/v1/connectors/httpparsers/PenaltiesHttpParser.scala

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
package v1.connectors.httpparsers
1818

1919
import play.api.http.Status._
20-
import play.api.libs.json.{ JsError, JsSuccess, JsValue, Json }
20+
import play.api.libs.json.{ JsError, JsSuccess, JsValue }
2121
import uk.gov.hmrc.http.{ HttpReads, HttpResponse }
2222
import utils.Logging
2323
import v1.connectors.Outcome
2424
import v1.models.errors._
2525
import v1.models.outcomes.ResponseWrapper
26-
import v1.models.response.penalties.{ PenaltiesErrorsHIP, PenaltiesErrorsIF, PenaltiesResponse }
26+
import v1.models.response.penalties.{ PenaltiesErrorsHIP, PenaltiesResponse }
2727

2828
object PenaltiesHttpParser extends Logging {
2929

@@ -47,46 +47,14 @@ object PenaltiesHttpParser extends Logging {
4747
}
4848

4949
def errorHelper(jsonString: JsValue): MtdError = {
50-
val penaltiesErrorsIF = jsonString.validate[PenaltiesErrorsIF]
51-
val penaltiesErrorsHIP = jsonString.validate[PenaltiesErrorsHIP]
52-
53-
(penaltiesErrorsIF, penaltiesErrorsHIP) match {
54-
case (JsSuccess(errorsIF, _), _) => convertToMtdErrorsIF(errorsIF)
55-
case (_, JsSuccess(errorsHIP, _)) => convertToMtdErrorsHIP(errorsHIP)
56-
case _ =>
57-
MtdError("SERVER_ERROR", "Unable to validate json error response", Some(jsonString))
50+
jsonString.validate[PenaltiesErrorsHIP] match {
51+
case JsSuccess(errorsHIP, _) => convertToMtdErrorsHIP(errorsHIP)
52+
case JsError(errors) =>
53+
MtdError("SERVER_ERROR", s"Unable to validate json error response with errors: $errors", Some(jsonString))
5854
}
5955
}
6056
}
6157

62-
private def convertToMtdErrorsIF(errorsIF: PenaltiesErrorsIF): MtdError = {
63-
val convertedErrors = errorsIF.failures.map { error =>
64-
error.code match {
65-
case "INVALID_IDVALUE" => PenaltiesInvalidIdValue
66-
case "INVALID_REGIME" => DownstreamError
67-
case "INVALID_IDTYPE" => DownstreamError
68-
case "INVALID_DATELIMIT" => DownstreamError
69-
case "INVALID_CORRELATIONID" => DownstreamError
70-
case "DUPLICATE_SUBMISSION" => DownstreamError
71-
case "INVALID_ID" => DownstreamError
72-
case "REQUEST_NOT_PROCESSED" => DownstreamError
73-
case "SERVER_ERROR" => DownstreamError
74-
case "SERVICE_UNAVAILABLE" => DownstreamError
75-
case _ => MtdError(error.code, error.reason)
76-
}
77-
}
78-
79-
val head = convertedErrors.head
80-
val error = if (convertedErrors.tail.isEmpty) {
81-
head
82-
} else if (convertedErrors.contains(DownstreamError)) {
83-
DownstreamError
84-
} else {
85-
MtdError("INVALID_REQUEST", "Invalid request penalty details", Some(Json.toJson(convertedErrors)))
86-
}
87-
error
88-
}
89-
9058
private def convertToMtdErrorsHIP(errorsHIP: PenaltiesErrorsHIP): MtdError = {
9159
val error = errorsHIP.errors
9260
error.code match {

app/v1/models/response/financialData/FinancialDataResponse.scala

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,6 @@ object FinancialDataResponse {
119119
implicit val writes: OWrites[FinancialDataResponse] = Json.writes[FinancialDataResponse]
120120
}
121121

122-
case class FinancialDataErrorsIF(failures: List[FinancialDataErrorIF])
123-
124-
object FinancialDataErrorsIF {
125-
implicit val format: OFormat[FinancialDataErrorsIF] = Json.format[FinancialDataErrorsIF]
126-
}
127-
128-
case class FinancialDataErrorIF(code: String, reason: String)
129-
130-
object FinancialDataErrorIF {
131-
implicit val format: OFormat[FinancialDataErrorIF] = Json.format[FinancialDataErrorIF]
132-
}
133-
134122
// Despite the name HIP 'errors' are always singular even if request has multiple issues
135123
case class FinancialDataErrorsHIP(errors: FinancialDataErrorHIP)
136124

app/v1/models/response/penalties/PenaltiesResponse.scala

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -320,19 +320,6 @@ object PenaltiesResponse {
320320
implicit val format: OFormat[PenaltiesResponse] = Json.format[PenaltiesResponse]
321321
}
322322

323-
324-
case class PenaltiesErrorsIF(failures: Seq[PenaltyErrorIF])
325-
326-
object PenaltiesErrorsIF {
327-
implicit val format: OFormat[PenaltiesErrorsIF] = Json.format[PenaltiesErrorsIF]
328-
}
329-
330-
case class PenaltyErrorIF(code: String, reason: String)
331-
332-
object PenaltyErrorIF {
333-
implicit val format: OFormat[PenaltyErrorIF] = Json.format[PenaltyErrorIF]
334-
}
335-
336323
// Despite the name HIP 'errors' are always singular even if request has multiple issues
337324
case class PenaltiesErrorsHIP(errors: PenaltiesErrorHIP)
338325

0 commit comments

Comments
 (0)