44
44
public class DefaultResponseErrorHandler implements ResponseErrorHandler {
45
45
46
46
/**
47
- * Delegates to {@link #hasError(HttpStatus)} with the response status code.
47
+ * Delegates to {@link #hasError(HttpStatus)} (for a standard status enum value) or
48
+ * {@link #hasError(int)} (for an unknown status code) with the response status code.
49
+ * @see ClientHttpResponse#getRawStatusCode()
50
+ * @see #hasError(HttpStatus)
51
+ * @see #hasError(int)
48
52
*/
49
53
@ Override
50
54
public boolean hasError (ClientHttpResponse response ) throws IOException {
@@ -55,16 +59,14 @@ public boolean hasError(ClientHttpResponse response) throws IOException {
55
59
56
60
/**
57
61
* Template method called from {@link #hasError(ClientHttpResponse)}.
58
- * <p>The default implementation checks if the given status code is
59
- * {@code HttpStatus.Series#CLIENT_ERROR CLIENT_ERROR} or
60
- * {@code HttpStatus.Series#SERVER_ERROR SERVER_ERROR}.
62
+ * <p>The default implementation checks {@link HttpStatus#isError()}.
61
63
* Can be overridden in subclasses.
62
64
* @param statusCode the HTTP status code as enum value
63
- * @return {@code true} if the response has an error; {@code false} otherwise
65
+ * @return {@code true} if the response indicates an error; {@code false} otherwise
66
+ * @see HttpStatus#isError()
64
67
*/
65
68
protected boolean hasError (HttpStatus statusCode ) {
66
- return (statusCode .series () == HttpStatus .Series .CLIENT_ERROR ||
67
- statusCode .series () == HttpStatus .Series .SERVER_ERROR );
69
+ return statusCode .isError ();
68
70
}
69
71
70
72
/**
@@ -74,16 +76,21 @@ protected boolean hasError(HttpStatus statusCode) {
74
76
* {@code HttpStatus.Series#SERVER_ERROR SERVER_ERROR}.
75
77
* Can be overridden in subclasses.
76
78
* @param unknownStatusCode the HTTP status code as raw value
77
- * @return {@code true} if the response has an error; {@code false} otherwise
79
+ * @return {@code true} if the response indicates an error; {@code false} otherwise
78
80
* @since 4.3.21
81
+ * @see HttpStatus.Series#CLIENT_ERROR
82
+ * @see HttpStatus.Series#SERVER_ERROR
79
83
*/
80
84
protected boolean hasError (int unknownStatusCode ) {
81
85
HttpStatus .Series series = HttpStatus .Series .resolve (unknownStatusCode );
82
86
return (series == HttpStatus .Series .CLIENT_ERROR || series == HttpStatus .Series .SERVER_ERROR );
83
87
}
84
88
85
89
/**
86
- * Delegates to {@link #handleError(ClientHttpResponse, HttpStatus)} with the response status code.
90
+ * Delegates to {@link #handleError(ClientHttpResponse, HttpStatus)} with the
91
+ * response status code.
92
+ * @throws UnknownHttpStatusCodeException in case of an unresolvable status code
93
+ * @see #handleError(ClientHttpResponse, HttpStatus)
87
94
*/
88
95
@ Override
89
96
public void handleError (ClientHttpResponse response ) throws IOException {
@@ -97,11 +104,13 @@ public void handleError(ClientHttpResponse response) throws IOException {
97
104
98
105
/**
99
106
* Handle the error in the given response with the given resolved status code.
100
- * <p>This default implementation throws a {@link HttpClientErrorException} if the response status code
101
- * is {@link org.springframework.http. HttpStatus.Series#CLIENT_ERROR}, a {@link HttpServerErrorException}
102
- * if it is {@link org.springframework.http. HttpStatus.Series#SERVER_ERROR},
103
- * and a {@link RestClientException } in other cases.
107
+ * <p>The default implementation throws an {@link HttpClientErrorException}
108
+ * if the status code is {@link HttpStatus.Series#CLIENT_ERROR}, an
109
+ * {@link HttpServerErrorException} if it is {@link HttpStatus.Series#SERVER_ERROR},
110
+ * and an {@link UnknownHttpStatusCodeException } in other cases.
104
111
* @since 5.0
112
+ * @see HttpClientErrorException#create
113
+ * @see HttpServerErrorException#create
105
114
*/
106
115
protected void handleError (ClientHttpResponse response , HttpStatus statusCode ) throws IOException {
107
116
String statusText = response .getStatusText ();
0 commit comments