diff --git a/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java b/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java index 2f6422e8a9ae..90c1b7a04a7b 100644 --- a/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java +++ b/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -103,9 +103,8 @@ public void handleError(ClientHttpResponse response) throws IOException { HttpStatus statusCode = HttpStatus.resolve(response.getRawStatusCode()); if (statusCode == null) { byte[] body = getResponseBody(response); - String message = getErrorMessage( - response.getRawStatusCode(), response.getStatusText(), - body, getCharset(response)); + String message = getErrorMessage(response.getRawStatusCode(), + response.getStatusText(), body, getCharset(response)); throw new UnknownHttpStatusCodeException(message, response.getRawStatusCode(), response.getStatusText(), response.getHeaders(), body, getCharset(response)); diff --git a/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java b/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java index 30d321fa5658..1cb23587d7ae 100644 --- a/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -183,6 +183,7 @@ public void handleErrorForCustomClientError() throws Exception { assertThat(actualUnknownHttpStatusCodeException.getRawStatusCode()).isEqualTo(statusCode); assertThat(actualUnknownHttpStatusCodeException.getStatusText()).isEqualTo(statusText); assertThat(actualUnknownHttpStatusCodeException.getResponseHeaders()).isEqualTo(headers); + assertThat(actualUnknownHttpStatusCodeException.getMessage()).contains(responseBody); assertThat(actualUnknownHttpStatusCodeException.getResponseBodyAsString()).isEqualTo(responseBody); } @@ -222,6 +223,7 @@ public void handleErrorForCustomServerError() throws Exception { assertThat(actualUnknownHttpStatusCodeException.getRawStatusCode()).isEqualTo(statusCode); assertThat(actualUnknownHttpStatusCodeException.getStatusText()).isEqualTo(statusText); assertThat(actualUnknownHttpStatusCodeException.getResponseHeaders()).isEqualTo(headers); + assertThat(actualUnknownHttpStatusCodeException.getMessage()).contains(responseBody); assertThat(actualUnknownHttpStatusCodeException.getResponseBodyAsString()).isEqualTo(responseBody); } @@ -241,6 +243,7 @@ public void bodyAvailableAfterHasErrorForUnknownStatusCode() throws Exception { assertThat(StreamUtils.copyToString(response.getBody(), StandardCharsets.UTF_8)).isEqualTo("Hello World"); } + private static class TestByteArrayInputStream extends ByteArrayInputStream { private boolean closed;