public class GoogleJsonResponseException
extends com.google.api.client.http.HttpResponseException
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()); } }
Constructor and Description |
---|
GoogleJsonResponseException(com.google.api.client.http.HttpResponseException.Builder builder,
GoogleJsonError details) |
Modifier and Type | Method and Description |
---|---|
static com.google.api.client.http.HttpResponse |
execute(com.google.api.client.json.JsonFactory jsonFactory,
com.google.api.client.http.HttpRequest request)
Executes an HTTP request using
HttpRequest.execute() , but throws a
GoogleJsonResponseException on error instead of HttpResponseException . |
static GoogleJsonResponseException |
from(com.google.api.client.json.JsonFactory jsonFactory,
com.google.api.client.http.HttpResponse response)
Returns a new instance of
GoogleJsonResponseException . |
GoogleJsonError |
getDetails()
Returns the Google JSON error details or
null for none (for example if response is not
JSON). |
computeMessageBuffer, getContent, getHeaders, getStatusCode, getStatusMessage, isSuccessStatusCode
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
public GoogleJsonResponseException(com.google.api.client.http.HttpResponseException.Builder builder, GoogleJsonError details)
builder
- builderdetails
- Google JSON error detailspublic final GoogleJsonError getDetails()
null
for none (for example if response is not
JSON).public static GoogleJsonResponseException from(com.google.api.client.json.JsonFactory jsonFactory, com.google.api.client.http.HttpResponse response)
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.
jsonFactory
- JSON factoryresponse
- HTTP responseGoogleJsonResponseException
public static com.google.api.client.http.HttpResponse execute(com.google.api.client.json.JsonFactory jsonFactory, com.google.api.client.http.HttpRequest request) throws GoogleJsonResponseException, IOException
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(); }
jsonFactory
- JSON factoryrequest
- HTTP requestHttpRequest.getThrowExceptionOnExecuteError()
)GoogleJsonResponseException
- for an HTTP error code (only if not
HttpRequest.getThrowExceptionOnExecuteError()
)IOException
- some other kind of I/O exceptionCopyright © 2010–2019 Google. All rights reserved.