com.google.api.client.googleapis.json
Class GoogleJsonResponseException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by java.io.IOException
              extended by com.google.api.client.http.HttpResponseException
                  extended by com.google.api.client.googleapis.json.GoogleJsonResponseException
All Implemented Interfaces:
Serializable

public class GoogleJsonResponseException
extends HttpResponseException

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());
    }
  }
 

Since:
1.6
Author:
Yaniv Inbar
See Also:
Serialized Form

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, getResponse, 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

getDetails

public final GoogleJsonError getDetails()
Returns the Google JSON error details or null for none (for example if response is not JSON).


getJsonFactory

@Deprecated
public final JsonFactory getJsonFactory()
Deprecated. (scheduled to be removed in 1.9)

Returns the JSON factory.


from

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.

Parameters:
jsonFactory - JSON factory
response - HTTP response
Returns:
new instance of GoogleJsonResponseException

execute

public static HttpResponse execute(JsonFactory jsonFactory,
                                   HttpRequest request)
                            throws GoogleJsonResponseException,
                                   IOException
Executes an HTTP request using HttpRequest.execute(), but throws a GoogleJsonResponseException on error instead of HttpResponseException.

Parameters:
jsonFactory - JSON factory
request - HTTP request
Returns:
HTTP response for an HTTP success code (or error code if HttpRequest.getThrowExceptionOnExecuteError())
Throws:
GoogleJsonResponseException - for an HTTP error code (only if not HttpRequest.getThrowExceptionOnExecuteError())
IOException - some other kind of I/O exception
Since:
1.7


Copyright © 2010-2012 Google. All Rights Reserved.