1717package v1 .connectors .httpparsers
1818
1919import play .api .http .Status ._
20- import play .api .libs .json .{ JsError , JsSuccess , JsValue , Json }
20+ import play .api .libs .json .{ JsError , JsSuccess , JsValue }
2121import uk .gov .hmrc .http .{ HttpReads , HttpResponse }
2222import utils .Logging
2323import v1 .connectors .Outcome
2424import v1 .models .errors ._
2525import v1 .models .outcomes .ResponseWrapper
26- import v1 .models .response .financialData .{ FinancialDataErrorsHIP , FinancialDataErrorsIF , FinancialDataResponse }
26+ import v1 .models .response .financialData .{ FinancialDataErrorsHIP , FinancialDataResponse }
2727
2828object 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 = {
0 commit comments