File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed
main/java/org/springframework/web/client
test/java/org/springframework/web/client Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,18 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
4545 * Delegates to {@link #hasError(HttpStatus)} with the response status code.
4646 */
4747 public boolean hasError (ClientHttpResponse response ) throws IOException {
48- return hasError (response .getStatusCode ());
48+ return hasError (getStatusCode (response ));
49+ }
50+
51+ private HttpStatus getStatusCode (ClientHttpResponse response ) throws IOException {
52+ HttpStatus statusCode ;
53+ try {
54+ statusCode = response .getStatusCode ();
55+ }
56+ catch (IllegalArgumentException ex ) {
57+ throw new RestClientException ("Unknown status code [" + response .getRawStatusCode () + "]" );
58+ }
59+ return statusCode ;
4960 }
5061
5162 /**
@@ -69,7 +80,7 @@ protected boolean hasError(HttpStatus statusCode) {
6980 * and a {@link RestClientException} in other cases.
7081 */
7182 public void handleError (ClientHttpResponse response ) throws IOException {
72- HttpStatus statusCode = response . getStatusCode ();
83+ HttpStatus statusCode = getStatusCode (response );
7384 HttpHeaders headers = response .getHeaders ();
7485 MediaType contentType = headers .getContentType ();
7586 Charset charset = contentType != null ? contentType .getCharSet () : null ;
Original file line number Diff line number Diff line change @@ -124,4 +124,16 @@ public void handleErrorNullResponse() throws Exception {
124124
125125 verify (response );
126126 }
127+
128+ // SPR-9406
129+
130+ @ Test (expected =RestClientException .class )
131+ public void unknownStatusCode () throws Exception {
132+ expect (response .getStatusCode ()).andThrow (new IllegalArgumentException ("No matching constant for 999" ));
133+ expect (response .getRawStatusCode ()).andReturn (999 );
134+
135+ replay (response );
136+
137+ handler .handleError (response );
138+ }
127139}
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ Changes in version 3.2 M2
77-------------------------
88
99* spring-test module now depends on junit:junit-dep
10-
10+ * raise RestClientException instead of IllegalArgumentException for unknown status codes
1111
1212Changes in version 3.2 M1 (2012-05-28)
1313--------------------------------------
You can’t perform that action at this time.
0 commit comments