Search in sources :

Example 1 with ErrorType

use of com.microsoft.live.OAuth.ErrorType in project LiveSDK-for-Android by liveservices.

the class OAuthErrorResponse method createFromJson.

/**
     * Static constructor that creates an OAuthErrorResponse from the given OAuth server's
     * JSONObject response
     * @param response from the OAuth server
     * @return A new instance of an OAuthErrorResponse from the given response
     * @throws LiveAuthException if there is an JSONException, or the error type cannot be found.
     */
public static OAuthErrorResponse createFromJson(JSONObject response) throws LiveAuthException {
    final String errorString;
    try {
        errorString = response.getString(OAuth.ERROR);
    } catch (JSONException e) {
        throw new LiveAuthException(ErrorMessages.SERVER_ERROR, e);
    }
    final ErrorType error;
    try {
        error = ErrorType.valueOf(errorString.toUpperCase());
    } catch (IllegalArgumentException e) {
        throw new LiveAuthException(ErrorMessages.SERVER_ERROR, e);
    } catch (NullPointerException e) {
        throw new LiveAuthException(ErrorMessages.SERVER_ERROR, e);
    }
    final Builder builder = new Builder(error);
    if (response.has(OAuth.ERROR_DESCRIPTION)) {
        final String errorDescription;
        try {
            errorDescription = response.getString(OAuth.ERROR_DESCRIPTION);
        } catch (JSONException e) {
            throw new LiveAuthException(ErrorMessages.CLIENT_ERROR, e);
        }
        builder.errorDescription(errorDescription);
    }
    if (response.has(OAuth.ERROR_URI)) {
        final String errorUri;
        try {
            errorUri = response.getString(OAuth.ERROR_URI);
        } catch (JSONException e) {
            throw new LiveAuthException(ErrorMessages.CLIENT_ERROR, e);
        }
        builder.errorUri(errorUri);
    }
    return builder.build();
}
Also used : ErrorType(com.microsoft.live.OAuth.ErrorType) JSONException(org.json.JSONException)

Aggregations

ErrorType (com.microsoft.live.OAuth.ErrorType)1 JSONException (org.json.JSONException)1