Package com.google.api.client.http
Class HttpResponseException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.io.IOException
-
- com.google.api.client.http.HttpResponseException
-
- All Implemented Interfaces:
Serializable
public class HttpResponseException extends IOException
Exception thrown when an error status code is detected in an HTTP response.Implementation is not thread safe.
- Since:
- 1.0
- Author:
- Yaniv Inbar
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HttpResponseException.Builder
Builder.
-
Constructor Summary
Constructors Modifier Constructor Description HttpResponseException(HttpResponse response)
Constructor that constructs a detail message from the given HTTP response that includes the status code, status message and HTTP response content.protected
HttpResponseException(HttpResponseException.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringBuilder
computeMessageBuffer(HttpResponse response)
Returns an exception message string builder to use for the given HTTP response.String
getContent()
Returns the HTTP response content ornull
for none.HttpHeaders
getHeaders()
Returns the HTTP response headers.int
getStatusCode()
Returns the HTTP status code or0
for none.String
getStatusMessage()
Returns the HTTP status message ornull
for none.boolean
isSuccessStatusCode()
Returns whether received a successful HTTP status code>= 200 && < 300
(seegetStatusCode()
).-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
-
-
-
Constructor Detail
-
HttpResponseException
public HttpResponseException(HttpResponse response)
Constructor that constructs a detail message from the given HTTP response that includes the status code, status message and HTTP response content.Callers of this constructor should call
HttpResponse.disconnect()
afterHttpResponseException
is instantiated. Example usage:try { throw new HttpResponseException(response); } finally { response.disconnect(); }
- Parameters:
response
- HTTP response
-
HttpResponseException
protected HttpResponseException(HttpResponseException.Builder builder)
- Parameters:
builder
- builder- Since:
- 1.14
-
-
Method Detail
-
isSuccessStatusCode
public final boolean isSuccessStatusCode()
Returns whether received a successful HTTP status code>= 200 && < 300
(seegetStatusCode()
).- Since:
- 1.7
-
getStatusCode
public final int getStatusCode()
Returns the HTTP status code or0
for none.- Since:
- 1.7
-
getStatusMessage
public final String getStatusMessage()
Returns the HTTP status message ornull
for none.- Since:
- 1.9
-
getHeaders
public HttpHeaders getHeaders()
Returns the HTTP response headers.- Since:
- 1.7
-
getContent
public final String getContent()
Returns the HTTP response content ornull
for none.- Since:
- 1.14
-
computeMessageBuffer
public static StringBuilder computeMessageBuffer(HttpResponse response)
Returns an exception message string builder to use for the given HTTP response.- Since:
- 1.7
-
-