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 30
30
* Spring's default implementation of the {@link ResponseErrorHandler} interface.
31
31
*
32
32
* <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)}.
36
37
*
37
38
* @author Arjen Poutsma
38
39
* @author Rossen Stoyanchev
40
+ * @author Juergen Hoeller
39
41
* @since 3.0
40
42
* @see RestTemplate#setErrorHandler
41
43
*/
Original file line number Diff line number Diff line change @@ -67,8 +67,8 @@ public void handleError() throws Exception {
67
67
handler .handleError (response );
68
68
fail ("expected HttpClientErrorException" );
69
69
}
70
- catch (HttpClientErrorException e ) {
71
- assertSame (headers , e .getResponseHeaders ());
70
+ catch (HttpClientErrorException ex ) {
71
+ assertSame (headers , ex .getResponseHeaders ());
72
72
}
73
73
}
74
74
@@ -109,4 +109,16 @@ public void unknownStatusCode() throws Exception {
109
109
handler .handleError (response );
110
110
}
111
111
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
+
112
124
}
You can’t perform that action at this time.
0 commit comments