File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed
main/java/org/springframework/web/client
test/java/org/springframework/web/client Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change 3030 * Spring's default implementation of the {@link ResponseErrorHandler} interface.
3131 *
3232 * <p>This error handler checks for the status code on the {@link ClientHttpResponse}:
33- * Any code with series {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR} or
34- * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR} is considered to be an
35- * error. This behavior can be changed by overriding the {@link #hasError(HttpStatus)} method.
33+ * Any code with series {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR}
34+ * or {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR} is considered to be
35+ * an error; this behavior can be changed by overriding the {@link #hasError(HttpStatus)}
36+ * method. Unknown status codes will be ignored by {@link #hasError(ClientHttpResponse)}.
3637 *
3738 * @author Arjen Poutsma
3839 * @author Rossen Stoyanchev
40+ * @author Juergen Hoeller
3941 * @since 3.0
4042 * @see RestTemplate#setErrorHandler
4143 */
Original file line number Diff line number Diff line change @@ -67,8 +67,8 @@ public void handleError() throws Exception {
6767 handler .handleError (response );
6868 fail ("expected HttpClientErrorException" );
6969 }
70- catch (HttpClientErrorException e ) {
71- assertSame (headers , e .getResponseHeaders ());
70+ catch (HttpClientErrorException ex ) {
71+ assertSame (headers , ex .getResponseHeaders ());
7272 }
7373 }
7474
@@ -109,4 +109,16 @@ public void unknownStatusCode() throws Exception {
109109 handler .handleError (response );
110110 }
111111
112+ @ Test // SPR-16108
113+ public void hasErrorForUnknownStatusCode () throws Exception {
114+ HttpHeaders headers = new HttpHeaders ();
115+ headers .setContentType (MediaType .TEXT_PLAIN );
116+
117+ given (response .getRawStatusCode ()).willReturn (999 );
118+ given (response .getStatusText ()).willReturn ("Custom status code" );
119+ given (response .getHeaders ()).willReturn (headers );
120+
121+ assertFalse (handler .hasError (response ));
122+ }
123+
112124}
You can’t perform that action at this time.
0 commit comments