// Perform a GET or POST to the API endpoint
try {
response = requestor.makeRequest();
} catch (Throwable t) {
throw new RestBANetworkException("RestBA request failed", t);
}
if (logger.isLoggable(INFO))
logger.info("Facebook responded with " + response);
// If we get any HTTP response code other than a 200 OK or 400 Bad
// Request
// or 401 Not Authorized or 403 Forbidden or 500 Internal Server Error,
// throw an exception.
if (HTTP_OK != response.getStatusCode()
&& HTTP_BAD_REQUEST != response.getStatusCode()
&& HTTP_UNAUTHORIZED != response.getStatusCode()
&& HTTP_INTERNAL_ERROR != response.getStatusCode()
&& HTTP_FORBIDDEN != response.getStatusCode())
throw new RestBANetworkException(
"RestBA request failed. HTTP code: "
+ response.getStatusCode());
String json = response.getBody();
// If the response contained an error code, throw an exception.
throwFacebookResponseStatusExceptionIfNecessary(json);
// If there was no response error information and this was a 500 or 401
// error, something weird happened on Facebook's end. Bail.
if (HTTP_INTERNAL_ERROR == response.getStatusCode()
|| HTTP_UNAUTHORIZED == response.getStatusCode())
throw new RestBANetworkException(
"RestBA request failed. HTTP code: "
+ response.getStatusCode());
return json;
}