Whether there will actually be a retry if this handler return
true. Some handlers may want to have an effect only when there will actually be a retry
after they handle their event (e.g. a handler that implements exponential backoff).
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Interface HttpUnsuccessfulResponseHandler (2.0.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.0.0 (latest)](/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpUnsuccessfulResponseHandler)\n- [1.47.1](/java/docs/reference/google-http-client/1.47.1/com.google.api.client.http.HttpUnsuccessfulResponseHandler)\n- [1.46.3](/java/docs/reference/google-http-client/1.46.3/com.google.api.client.http.HttpUnsuccessfulResponseHandler)\n- [1.45.3](/java/docs/reference/google-http-client/1.45.3/com.google.api.client.http.HttpUnsuccessfulResponseHandler)\n- [1.44.2](/java/docs/reference/google-http-client/1.44.2/com.google.api.client.http.HttpUnsuccessfulResponseHandler)\n- [1.43.2](/java/docs/reference/google-http-client/1.43.2/com.google.api.client.http.HttpUnsuccessfulResponseHandler)\n- [1.42.3](/java/docs/reference/google-http-client/1.42.3/com.google.api.client.http.HttpUnsuccessfulResponseHandler)\n- [1.41.8](/java/docs/reference/google-http-client/1.41.8/com.google.api.client.http.HttpUnsuccessfulResponseHandler) \n\n public interface HttpUnsuccessfulResponseHandler\n\nInterface which handles abnormal HTTP responses (in other words not 2XX).\n\nFor example, this might be used to refresh an OAuth 2 token:\n\npublic static class RefreshTokenHandler implements HttpUnsuccessfulResponseHandler {\npublic boolean handleResponse(\nHttpRequest request, HttpResponse response, boolean retrySupported) throws IOException {\nif (response.getStatusCode() == HttpStatusCodes.STATUS_CODE_UNAUTHORIZED) {\nrefreshToken();\n}\nreturn false;\n}\n}\n\nSample usage with a request factory:\n\npublic static HttpRequestFactory createRequestFactory(HttpTransport transport) {\nfinal RefreshTokenHandler handler = new RefreshTokenHandler();\nreturn transport.createRequestFactory(new HttpRequestInitializer() {\npublic void initialize(HttpRequest request) {\nrequest.setUnsuccessfulResponseHandler(handler);\n}\n});\n}\n\nMore complex usage example:\n\npublic static HttpRequestFactory createRequestFactory2(HttpTransport transport) {\nfinal RefreshTokenHandler handler = new RefreshTokenHandler();\nreturn transport.createRequestFactory(new HttpRequestInitializer() {\npublic void initialize(HttpRequest request) {\nrequest.setUnsuccessfulResponseHandler(new HttpUnsuccessfulResponseHandler() {\npublic boolean handleResponse(\nHttpRequest request, HttpResponse response, boolean retrySupported)\nthrows IOException {\nreturn handler.handleResponse(request, response, retrySupported);\n}\n});\n}\n});\n}\n\nMethods\n-------\n\n### handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry)\n\n public abstract boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry)\n\nHandler that will be invoked when an abnormal response is received. There are a few simple\nrules that one must follow:\n\n- If you modify the request object or modify its execute interceptors in a way that should resolve the error, you must return true to issue a retry.\n- Do not read from the content stream, this will prevent the eventual end user from having access to it."]]