4444public class DefaultResponseErrorHandler implements ResponseErrorHandler {
4545
4646 /**
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)
4852 */
4953 @ Override
5054 public boolean hasError (ClientHttpResponse response ) throws IOException {
@@ -55,16 +59,14 @@ public boolean hasError(ClientHttpResponse response) throws IOException {
5559
5660 /**
5761 * 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()}.
6163 * Can be overridden in subclasses.
6264 * @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()
6467 */
6568 protected boolean hasError (HttpStatus statusCode ) {
66- return (statusCode .series () == HttpStatus .Series .CLIENT_ERROR ||
67- statusCode .series () == HttpStatus .Series .SERVER_ERROR );
69+ return statusCode .isError ();
6870 }
6971
7072 /**
@@ -74,16 +76,21 @@ protected boolean hasError(HttpStatus statusCode) {
7476 * {@code HttpStatus.Series#SERVER_ERROR SERVER_ERROR}.
7577 * Can be overridden in subclasses.
7678 * @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
7880 * @since 4.3.21
81+ * @see HttpStatus.Series#CLIENT_ERROR
82+ * @see HttpStatus.Series#SERVER_ERROR
7983 */
8084 protected boolean hasError (int unknownStatusCode ) {
8185 HttpStatus .Series series = HttpStatus .Series .resolve (unknownStatusCode );
8286 return (series == HttpStatus .Series .CLIENT_ERROR || series == HttpStatus .Series .SERVER_ERROR );
8387 }
8488
8589 /**
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)
8794 */
8895 @ Override
8996 public void handleError (ClientHttpResponse response ) throws IOException {
@@ -97,11 +104,13 @@ public void handleError(ClientHttpResponse response) throws IOException {
97104
98105 /**
99106 * 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.
104111 * @since 5.0
112+ * @see HttpClientErrorException#create
113+ * @see HttpServerErrorException#create
105114 */
106115 protected void handleError (ClientHttpResponse response , HttpStatus statusCode ) throws IOException {
107116 String statusText = response .getStatusText ();
0 commit comments