Use response decorator to check if error handled
Closes gh-33980
This commit is contained in:
parent
431d726dc6
commit
fa01e9c566
|
|
@ -136,18 +136,29 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void handleError(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {
|
public void handleError(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {
|
||||||
handleError(response);
|
|
||||||
|
// For backwards compatibility try handle(response) first
|
||||||
|
HandleErrorResponseDecorator decorator = new HandleErrorResponseDecorator(response);
|
||||||
|
handleError(decorator);
|
||||||
|
if (decorator.isHandled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
handleError(response, response.getStatusCode(), url, method);
|
handleError(response, response.getStatusCode(), url, method);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
* <p>As of 6.2.1 this method is a no-op unless overridden.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("removal")
|
@SuppressWarnings("removal")
|
||||||
@Override
|
@Override
|
||||||
public void handleError(ClientHttpResponse response) throws IOException {
|
public void handleError(ClientHttpResponse response) throws IOException {
|
||||||
// no-op, but here for backwards compatibility
|
|
||||||
|
// Called via handleError(url, method, response)
|
||||||
|
if (response instanceof HandleErrorResponseDecorator decorator) {
|
||||||
|
decorator.setNotHandled();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called directly, so do handle
|
||||||
|
handleError(response, response.getStatusCode(), null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -277,4 +288,22 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static class HandleErrorResponseDecorator extends ClientHttpResponseDecorator {
|
||||||
|
|
||||||
|
private boolean handled = true;
|
||||||
|
|
||||||
|
public HandleErrorResponseDecorator(ClientHttpResponse delegate) {
|
||||||
|
super(delegate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNotHandled() {
|
||||||
|
this.handled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHandled() {
|
||||||
|
return this.handled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,6 @@ public interface ResponseErrorHandler {
|
||||||
*/
|
*/
|
||||||
@Deprecated(since = "6.2.1", forRemoval = true)
|
@Deprecated(since = "6.2.1", forRemoval = true)
|
||||||
default void handleError(ClientHttpResponse response) throws IOException {
|
default void handleError(ClientHttpResponse response) throws IOException {
|
||||||
// no-op unless overridden
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue