public class GoogleJsonResponseException extends HttpResponseExceptionException thrown when an error status code is detected in an HTTP response to a Google API that uses the JSON format, using the format specified in Error Responses.
To execute a request, call #execute(JsonFactory, HttpRequest). This will throw a GoogleJsonResponseException on an error response. To get the structured details, use #getDetails().
static void executeShowingError(JsonFactory factory, HttpRequest request) throws IOException {
try {
GoogleJsonResponseException.execute(factory, request);
} catch (GoogleJsonResponseException e) {
System.err.println(e.getDetails());
}
}
Static Methods
execute(JsonFactory jsonFactory, HttpRequest request)
public static HttpResponse execute(JsonFactory jsonFactory, HttpRequest request)Executes an HTTP request using HttpRequest#execute(), but throws a GoogleJsonResponseException on error instead of HttpResponseException.
Callers should call HttpResponse#disconnect when the returned HTTP response object is no longer needed. However, HttpResponse#disconnect does not have to be called if the response stream is properly closed. Example usage:
HttpResponse response = GoogleJsonResponseException.execute(jsonFactory, request);
try {
// process the HTTP response object
} finally {
response.disconnect();
}
| Name | Description |
| jsonFactory | com.google.api.client.json.JsonFactoryJSON factory |
| request | com.google.api.client.http.HttpRequestHTTP request |
| Type | Description |
| com.google.api.client.http.HttpResponse | HTTP response for an HTTP success code (or error code if HttpRequest#getThrowExceptionOnExecuteError()) |
| Type | Description |
for an HTTP error code (only if not HttpRequest#getThrowExceptionOnExecuteError()) |
|
| IOException | for an HTTP error code (only if not HttpRequest#getThrowExceptionOnExecuteError()) |
from(JsonFactory jsonFactory, HttpResponse response)
public static GoogleJsonResponseException from(JsonFactory jsonFactory, HttpResponse response)Returns a new instance of GoogleJsonResponseException.
If there is a JSON error response, it is parsed using GoogleJsonError, which can be inspected using #getDetails(). Otherwise, the full response content is read and included in the exception message.
| Name | Description |
| jsonFactory | com.google.api.client.json.JsonFactoryJSON factory |
| response | com.google.api.client.http.HttpResponseHTTP response |
| Type | Description |
| GoogleJsonResponseException | new instance of GoogleJsonResponseException |
Constructors
GoogleJsonResponseException(HttpResponseException.Builder builder, GoogleJsonError details)
public GoogleJsonResponseException(HttpResponseException.Builder builder, GoogleJsonError details)| Name | Description |
| builder | com.google.api.client.http.HttpResponseException.Builderbuilder |
| details | GoogleJsonErrorGoogle JSON error details |
Methods
getDetails()
public final GoogleJsonError getDetails()Returns the Google JSON error details or null for none (for example if response is not
JSON).
| Type | Description |
| GoogleJsonError |