public class GoogleJsonResponseException extends 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()); } }
HttpResponseException.Builder
Constructor and Description |
---|
GoogleJsonResponseException(HttpResponseException.Builder builder,
GoogleJsonError details) |
Modifier and Type | Method and Description |
---|---|
static HttpResponse |
execute(JsonFactory jsonFactory,
HttpRequest request)
Executes an HTTP request using
HttpRequest.execute() , but throws a GoogleJsonResponseException on error instead of HttpResponseException . |
static GoogleJsonResponseException |
from(JsonFactory jsonFactory,
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(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(JsonFactory jsonFactory, 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 HttpResponse execute(JsonFactory jsonFactory, 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–2020 Google. All rights reserved.