18
18
19
19
import java .io .IOException ;
20
20
21
- import org .springframework .web .client .HttpClientErrorException ;
22
- import org .springframework .web .client .RestClientException ;
23
- import org .springframework .web .client .HttpServerErrorException ;
24
21
import org .springframework .http .HttpStatus ;
25
22
import org .springframework .http .client .ClientHttpResponse ;
26
23
27
24
/**
28
25
* Default implementation of the {@link ResponseErrorHandler} interface.
29
26
*
30
27
* <p>This error handler checks for the status code on the {@link ClientHttpResponse}: any code with series
31
- * {@link HttpStatus.Series#CLIENT_ERROR} or {@link HttpStatus.Series#SERVER_ERROR} is considered to be an error.
28
+ * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR} or
29
+ * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR} is considered to be an error.
32
30
* This behavior can be changed by overriding the {@link #hasError(HttpStatus)} method.
33
31
*
34
32
* @author Arjen Poutsma
@@ -46,18 +44,24 @@ public boolean hasError(ClientHttpResponse response) throws IOException {
46
44
47
45
/**
48
46
* Template method called from {@link #hasError(ClientHttpResponse)}.
49
- * <p>The default implementation checks if the given status code is {@link HttpStatus.Series#CLIENT_ERROR}
50
- * or {@link HttpStatus.Series#SERVER_ERROR}. Can be overridden in subclasses.
47
+ * <p>The default implementation checks if the given status code is
48
+ * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR CLIENT_ERROR}
49
+ * or {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR SERVER_ERROR}. Can be overridden in subclasses.
51
50
* @param statusCode the HTTP status code
52
51
* @return <code>true</code> if the response has an error; <code>false</code> otherwise
53
- * @see HttpStatus.Series#CLIENT_ERROR
54
- * @see HttpStatus.Series#SERVER_ERROR
55
52
*/
56
53
protected boolean hasError (HttpStatus statusCode ) {
57
54
return (statusCode .series () == HttpStatus .Series .CLIENT_ERROR ||
58
55
statusCode .series () == HttpStatus .Series .SERVER_ERROR );
59
56
}
60
57
58
+ /**
59
+ * {@inheritDoc}
60
+ * <p>The default implementation throws a {@link HttpClientErrorException} if the response status code is
61
+ * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR}, a {@link HttpServerErrorException} if it is
62
+ * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}, and a {@link RestClientException} in other
63
+ * cases.
64
+ */
61
65
public void handleError (ClientHttpResponse response ) throws IOException {
62
66
HttpStatus statusCode = response .getStatusCode ();
63
67
switch (statusCode .series ()) {
0 commit comments