@@ -136,18 +136,29 @@ protected boolean hasError(int statusCode) {
136
136
*/
137
137
@ Override
138
138
public void handleError (URI url , HttpMethod method , ClientHttpResponse response ) throws IOException {
139
- handleError (response );
139
+
140
+ // For backwards compatibility try handle(response) first
141
+ HandleErrorResponseDecorator decorator = new HandleErrorResponseDecorator (response );
142
+ handleError (decorator );
143
+ if (decorator .isHandled ()) {
144
+ return ;
145
+ }
146
+
140
147
handleError (response , response .getStatusCode (), url , method );
141
148
}
142
149
143
- /**
144
- * {@inheritDoc}
145
- * <p>As of 6.2.1 this method is a no-op unless overridden.
146
- */
147
150
@ SuppressWarnings ("removal" )
148
151
@ Override
149
152
public void handleError (ClientHttpResponse response ) throws IOException {
150
- // no-op, but here for backwards compatibility
153
+
154
+ // Called via handleError(url, method, response)
155
+ if (response instanceof HandleErrorResponseDecorator decorator ) {
156
+ decorator .setNotHandled ();
157
+ return ;
158
+ }
159
+
160
+ // Called directly, so do handle
161
+ handleError (response , response .getStatusCode (), null , null );
151
162
}
152
163
153
164
/**
@@ -277,4 +288,22 @@ public InputStream getBody() {
277
288
};
278
289
}
279
290
291
+
292
+ private static class HandleErrorResponseDecorator extends ClientHttpResponseDecorator {
293
+
294
+ private boolean handled = true ;
295
+
296
+ public HandleErrorResponseDecorator (ClientHttpResponse delegate ) {
297
+ super (delegate );
298
+ }
299
+
300
+ public void setNotHandled () {
301
+ this .handled = false ;
302
+ }
303
+
304
+ public boolean isHandled () {
305
+ return this .handled ;
306
+ }
307
+ }
308
+
280
309
}
0 commit comments