private FacebookRequestError( int requestStatusCode, int errorCode, int subErrorCode, String errorType, String errorMessage, String errorUserTitle, String errorUserMessage, boolean errorIsTransient, JSONObject requestResultBody, JSONObject requestResult, Object batchRequestResult, HttpURLConnection connection, FacebookException exception) { this.requestStatusCode = requestStatusCode; this.errorCode = errorCode; this.subErrorCode = subErrorCode; this.errorType = errorType; this.errorMessage = errorMessage; this.requestResultBody = requestResultBody; this.requestResult = requestResult; this.batchRequestResult = batchRequestResult; this.connection = connection; this.errorUserTitle = errorUserTitle; this.errorUserMessage = errorUserMessage; boolean isLocalException = false; if (exception != null) { this.exception = exception; isLocalException = true; } else { this.exception = new FacebookServiceException(this, errorMessage); } FacebookRequestErrorClassification errorClassification = getErrorClassification(); this.category = isLocalException ? Category.OTHER : errorClassification.classify(errorCode, subErrorCode, errorIsTransient); this.errorRecoveryMessage = errorClassification.getRecoveryMessage(this.category); }
static synchronized FacebookRequestErrorClassification getErrorClassification() { FacebookRequestErrorClassification errorClassification; Utility.FetchedAppSettings appSettings = Utility.getAppSettingsWithoutQuery(FacebookSdk.getApplicationId()); if (appSettings == null) { return FacebookRequestErrorClassification.getDefaultErrorClassification(); } return appSettings.getErrorClassification(); }
private static GraphResponse createResponseFromObject( GraphRequest request, HttpURLConnection connection, Object object, Object originalResult ) throws JSONException { if (object instanceof JSONObject) { JSONObject jsonObject = (JSONObject) object; FacebookRequestError error = FacebookRequestError.checkResponseAndCreateError( jsonObject, originalResult, connection); if (error != null) { if (error.getErrorCode() == FacebookRequestErrorClassification.EC_INVALID_TOKEN && Utility.isCurrentAccessToken(request.getAccessToken())) { AccessToken.setCurrentAccessToken(null); } return new GraphResponse(request, connection, error); } Object body = Utility.getStringPropertyAsJSON( jsonObject, BODY_KEY, NON_JSON_RESPONSE_PROPERTY); if (body instanceof JSONObject) { return new GraphResponse(request, connection, body.toString(), (JSONObject)body); } else if (body instanceof JSONArray) { return new GraphResponse(request, connection, body.toString(), (JSONArray)body); } // We didn't get a body we understand how to handle, so pretend we got nothing. object = JSONObject.NULL; } if (object == JSONObject.NULL) { return new GraphResponse(request, connection, object.toString(), (JSONObject)null); } else { throw new FacebookException("Got unexpected object type in response, class: " + object.getClass().getSimpleName()); } }