Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ protected boolean hasError(int unknownStatusCode) {
public void handleError(ClientHttpResponse response) throws IOException {
HttpStatus statusCode = HttpStatus.resolve(response.getRawStatusCode());
if (statusCode == null) {
byte[] responseBody = getResponseBody(response);
String message = getErrorMessage(
response.getRawStatusCode(), response.getStatusText(),
getResponseBody(response), getCharset(response));
responseBody, getCharset(response));
throw new UnknownHttpStatusCodeException(message,
response.getRawStatusCode(), response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
response.getHeaders(), responseBody, getCharset(response));
}
handleError(response, statusCode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.catchThrowableOfType;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;

Expand Down Expand Up @@ -213,6 +214,25 @@ public void bodyAvailableAfterHasErrorForUnknownStatusCode() throws Exception {
}


@Test
public void bodyAvailableAfterHandlingUnknownStatusClientError() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
TestByteArrayInputStream body = new TestByteArrayInputStream("Hello World".getBytes(StandardCharsets.UTF_8));

given(response.getRawStatusCode()).willReturn(432);
given(response.getStatusText()).willReturn("Custom status code");
given(response.getHeaders()).willReturn(headers);
given(response.getBody()).willReturn(body);

UnknownHttpStatusCodeException caught = catchThrowableOfType(() -> handler.handleError(response),
UnknownHttpStatusCodeException.class);

assertThat(caught.getResponseBodyAsString()).isEqualTo("Hello World");

}


private static class TestByteArrayInputStream extends ByteArrayInputStream {

private boolean closed;
Expand Down