|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Throwable
java.lang.Exception
java.io.IOException
com.google.api.client.http.HttpResponseException
com.google.api.client.googleapis.json.GoogleJsonResponseException
public class GoogleJsonResponseException
Exception 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()); } }
Method Summary | |
---|---|
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). |
JsonFactory |
getJsonFactory()
Deprecated. (scheduled to be removed in 1.9) |
Methods inherited from class com.google.api.client.http.HttpResponseException |
---|
computeMessageBuffer, getHeaders, getStatusCode, getStatusMessage, isSuccessStatusCode |
Methods inherited from class java.lang.Throwable |
---|
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public final GoogleJsonError getDetails()
null
for none (for example if response is not
JSON).
@Deprecated public final JsonFactory getJsonFactory()
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 response
GoogleJsonResponseException
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 request
HttpRequest.getThrowExceptionOnExecuteError()
)
GoogleJsonResponseException
- for an HTTP error code (only if not
HttpRequest.getThrowExceptionOnExecuteError()
)
IOException
- some other kind of I/O exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |