Commit ab4952a 1 parent 0e3a1d8 commit ab4952a Copy full SHA for ab4952a
File tree 3 files changed +26
-3
lines changed
main/java/org/springframework/web/client
test/java/org/springframework/web/client
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 {
45
45
* Delegates to {@link #hasError(HttpStatus)} with the response status code.
46
46
*/
47
47
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 ;
49
60
}
50
61
51
62
/**
@@ -69,7 +80,7 @@ protected boolean hasError(HttpStatus statusCode) {
69
80
* and a {@link RestClientException} in other cases.
70
81
*/
71
82
public void handleError (ClientHttpResponse response ) throws IOException {
72
- HttpStatus statusCode = response . getStatusCode ();
83
+ HttpStatus statusCode = getStatusCode (response );
73
84
HttpHeaders headers = response .getHeaders ();
74
85
MediaType contentType = headers .getContentType ();
75
86
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 {
124
124
125
125
verify (response );
126
126
}
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
+ }
127
139
}
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ Changes in version 3.2 M2
7
7
-------------------------
8
8
9
9
* spring-test module now depends on junit:junit-dep
10
-
10
+ * raise RestClientException instead of IllegalArgumentException for unknown status codes
11
11
12
12
Changes in version 3.2 M1 (2012-05-28)
13
13
--------------------------------------
You can’t perform that action at this time.
0 commit comments