try {
// If this is not an object, it's not an error response.
if (!json.startsWith("{"))
return;
JsonObject errorObject = null;
// We need to swallow exceptions here because it's possible to get a legit
// Facebook response that contains illegal JSON (e.g.
// users.getLoggedInUser returning 1240077) - we're only interested in
// whether or not there's an error_code field present.
try {
errorObject = new JsonObject(json);
} catch (JsonException e) {}
if (errorObject == null || !errorObject.has(BATCH_ERROR_ATTRIBUTE_NAME)
|| !errorObject.has(BATCH_ERROR_DESCRIPTION_ATTRIBUTE_NAME))
return;
throw legacyFacebookExceptionMapper.exceptionForTypeAndMessage(errorObject.getInt(BATCH_ERROR_ATTRIBUTE_NAME),
httpStatusCode, null, errorObject.getString(BATCH_ERROR_DESCRIPTION_ATTRIBUTE_NAME));
} catch (JsonException e) {
throw new FacebookJsonMappingException("Unable to process the Facebook API response", e);
}
}