Skip to content

Commit bdf2324

Browse files
Add response ID field
1 parent e833617 commit bdf2324

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ hs_err_pid*
2323
/ibanity-java.iml
2424
/.idea/
2525
/target/
26+
27+
.vscode/

src/main/java/com/ibanity/apis/client/jsonapi/FinancialInstitutionResponseApiModel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ public class FinancialInstitutionResponseApiModel {
1717
private Instant timestamp;
1818
private String requestUri;
1919
private Integer statusCode;
20+
private String responseId;
2021
}

src/main/java/com/ibanity/apis/client/mappers/IbanityErrorMapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static IbanityError map(IbanityErrorApiModel ibanityErrorApiModel) {
2525
.statusCode(financialInstitutionResponseApiModel.getStatusCode())
2626
.body(parseBody(financialInstitutionResponseApiModel))
2727
.requestId(financialInstitutionResponseApiModel.getRequestId())
28+
.responseId(financialInstitutionResponseApiModel.getResponseId())
2829
.timestamp(financialInstitutionResponseApiModel.getTimestamp())
2930
.build();
3031
errorMetaBuilder.financialInstitutionResponse(financialInstitutionResponse);

src/main/java/com/ibanity/apis/client/models/FinancialInstitutionResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ public class FinancialInstitutionResponse {
1717
private Instant timestamp;
1818
private String requestUri;
1919
private Integer statusCode;
20+
private String responseId;
2021
}

src/test/java/com/ibanity/apis/client/http/handler/IbanityResponseHandlerTest.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ void handleResponse_whenServerError_thenThrowIbanityServerSideException() {
5757
assertThat(actual).isEqualToComparingFieldByFieldRecursively(new IbanityServerException(createExpectedErrorsWithJson(), 500, REQUEST_ID));
5858
}
5959

60+
@Test
61+
void handleResponse_whenServerErrorWithResponseID_thenThrowIbanityServiceSideExceptionWithResponseID() {
62+
// language=JSON
63+
String expected = errorPayloadWithResponseIdJson();
64+
65+
when(httpResponse.getEntity()).thenReturn(EntityBuilder.create().setText(expected).build());
66+
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(dummyProtocolVersion(), 500, ""));
67+
when(httpResponse.getFirstHeader(IBANITY_REQUEST_ID_HEADER))
68+
.thenReturn(new BasicHeader(IBANITY_REQUEST_ID_HEADER, REQUEST_ID));
69+
70+
IbanityServerException actual = assertThrows(IbanityServerException.class,
71+
() -> ibanityResponseHandler.handleResponse(httpResponse));
72+
73+
actual.getErrors().forEach(error ->
74+
assertThat(error.getMeta().getFinancialInstitutionResponse().getResponseId())
75+
.isEqualTo("gdhed515hrtzehg")
76+
);
77+
}
78+
6079
@Test
6180
void handleResponse_whenResourceNotFound_thenThrowIbanityClientSideException() {
6281
//language=JSON
@@ -160,6 +179,37 @@ private String errorPayloadWithJson() {
160179
"}";
161180
}
162181

182+
private String errorPayloadWithResponseIdJson() {
183+
//language=JSON
184+
return "{\n" +
185+
" \"errors\": [\n" +
186+
" {\n" +
187+
" \"code\": \"invalidCredentials\",\n" +
188+
" \"detail\": \"Your credentials are invalid.\",\n" +
189+
" \"meta\": {\n" +
190+
" \"financialInstitutionResponse\": {\n" +
191+
" \"statusCode\": 500,\n" +
192+
" \"body\": {\n" +
193+
" \"tppMessages\": [\n" +
194+
" {\n" +
195+
" \"category\": \"ERROR\",\n" +
196+
" \"code\": \"NOT_FOUND\",\n" +
197+
" \"text\": \"3.2 - Not Found\"\n" +
198+
" }\n" +
199+
" ]\n" +
200+
" },\n" +
201+
" \"requestId\": \"354fwfwef4w684\",\n" +
202+
" \"responseId\": \"gdhed515hrtzehg\",\n" +
203+
" \"timestamp\": \"2019-05-09T09:18:00.000Z\",\n" +
204+
" \"requestUri\": \"http://google.com\"\n" +
205+
" }\n" +
206+
" " +
207+
"}\n" +
208+
" }\n" +
209+
" ]\n" +
210+
"}";
211+
}
212+
163213
private ProtocolVersion dummyProtocolVersion() {
164214
return new ProtocolVersion("", 0, 0);
165215
}

0 commit comments

Comments
 (0)