private OAuthWebView . AuthFailure getAuthFailure ( Exception e ) { String error = getString ( R . string . boxsdk_Authentication_fail ) ; if ( e != null ) { // Get the proper exception Throwable ex = e instanceof ExecutionException ? ( ( ExecutionException ) e ) . getCause ( ) : e ; if ( ex instanceof BoxException ) { BoxError boxError = ( ( BoxException ) ex ) . getAsBoxError ( ) ; if ( boxError != null ) { if ( ( ( BoxException ) ex ) . getResponseCode ( ) == HttpURLConnection . HTTP_FORBIDDEN || ( ( BoxException ) ex ) . getResponseCode ( ) == HttpURLConnection . HTTP_UNAUTHORIZED || boxError . getError ( ) . equals ( "unauthorized_device" ) ) { error += ":" + getResources ( ) . getText ( R . string . boxsdk_Authentication_fail_forbidden ) + "\n" ; } else { error += ":" ; } error += boxError . getErrorDescription ( ) ; return new OAuthWebView . AuthFailure ( OAuthWebView . AuthFailure . TYPE_AUTHENTICATION_UNAUTHORIZED , error ) ; } } error += ":" + ex ; } return new OAuthWebView . AuthFailure ( OAuthWebView . AuthFailure . TYPE_GENERIC , error ) ; }
Takes an auth exception and converts it to an AuthFailure so it can be properly handled