com.google.api.client.auth.oauth2.TokenErrorResponse

Here are the examples of the java api class com.google.api.client.auth.oauth2.TokenErrorResponse taken from open source projects.

1. LenientTokenResponseException#from()

Project: android-oauth-client
File: LenientTokenResponseException.java
/**
     * Returns a new instance of {@link LenientTokenResponseException}.
     * <p>
     * If there is a JSON error response, it is parsed using
     * {@link TokenErrorResponse}, which can be inspected using
     * {@link #getDetails()}. Otherwise, the full response content is read and
     * included in the exception message.
     * </p>
     * 
     * @param jsonFactory JSON factory
     * @param readResponse an HTTP response that has already been read
     * @param responseContent the content String of the HTTP response
     * @return new instance of {@link TokenErrorResponse}
     */
public static LenientTokenResponseException from(JsonFactory jsonFactory, HttpResponse readResponse, String responseContent) {
    HttpResponseException.Builder builder = new HttpResponseException.Builder(readResponse.getStatusCode(), readResponse.getStatusMessage(), readResponse.getHeaders());
    // details
    Preconditions.checkNotNull(jsonFactory);
    TokenErrorResponse details = null;
    String detailString = null;
    String contentType = readResponse.getContentType();
    try {
        if (/* !response.isSuccessStatusCode() && */
        true && contentType != null && HttpMediaType.equalsIgnoreParameters(Json.MEDIA_TYPE, contentType)) {
            details = readResponse.getRequest().getParser().parseAndClose(new StringReader(responseContent), TokenErrorResponse.class);
            detailString = details.toPrettyString();
        } else {
            detailString = responseContent;
        }
    } catch (IOException exception) {
        exception.printStackTrace();
    }
    // message
    StringBuilder message = HttpResponseException.computeMessageBuffer(readResponse);
    if (!com.google.api.client.util.Strings.isNullOrEmpty(detailString)) {
        message.append(StringUtils.LINE_SEPARATOR).append(detailString);
        builder.setContent(detailString);
    }
    builder.setMessage(message.toString());
    return new LenientTokenResponseException(builder, details);
}