Package com.restfb.exception.generator
Class DefaultFacebookExceptionGenerator
- java.lang.Object
-
- com.restfb.exception.generator.DefaultFacebookExceptionGenerator
-
- All Implemented Interfaces:
FacebookExceptionGenerator
public class DefaultFacebookExceptionGenerator extends Object implements FacebookExceptionGenerator
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
DefaultFacebookExceptionGenerator.DefaultGraphFacebookExceptionMapper
A canned implementation ofFacebookExceptionMapper
that maps Graph API exceptions.
-
Field Summary
Fields Modifier and Type Field Description protected FacebookExceptionMapper
graphFacebookExceptionMapper
Knows how to map Graph API exceptions to formal Java exception types.-
Fields inherited from interface com.restfb.exception.generator.FacebookExceptionGenerator
BATCH_ERROR_ATTRIBUTE_NAME, BATCH_ERROR_DESCRIPTION_ATTRIBUTE_NAME, ERROR_ATTRIBUTE_NAME, ERROR_CODE_ATTRIBUTE_NAME, ERROR_IS_TRANSIENT_NAME, ERROR_MESSAGE_ATTRIBUTE_NAME, ERROR_SUBCODE_ATTRIBUTE_NAME, ERROR_TYPE_ATTRIBUTE_NAME, ERROR_USER_MSG_ATTRIBUTE_NAME, ERROR_USER_TITLE_ATTRIBUTE_NAME
-
-
Constructor Summary
Constructors Constructor Description DefaultFacebookExceptionGenerator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ExceptionInformation
createFacebookResponseTypeAndMessageContainer(JsonObject errorObject, Integer httpStatusCode)
protected FacebookExceptionMapper
createGraphFacebookExceptionMapper()
Specifies how we map Graph API exception types/messages to real Java exceptions.protected JsonObject
silentlyCreateObjectFromString(String json)
create aJsonObject
from String and swallow possible JsonExceptionprotected void
skipResponseStatusExceptionParsing(String json)
checks if a string may be a json and contains a error string somewhere, this is used for speedup the error parsingvoid
throwBatchFacebookResponseStatusExceptionIfNecessary(String json, Integer httpStatusCode)
If theerror
anderror_description
JSON fields are present, we've got a response status error for this batch API call.void
throwFacebookResponseStatusExceptionIfNecessary(String json, Integer httpStatusCode)
Throws an exception if Facebook returned an error response.
-
-
-
Field Detail
-
graphFacebookExceptionMapper
protected FacebookExceptionMapper graphFacebookExceptionMapper
Knows how to map Graph API exceptions to formal Java exception types.
-
-
Constructor Detail
-
DefaultFacebookExceptionGenerator
public DefaultFacebookExceptionGenerator()
-
-
Method Detail
-
throwFacebookResponseStatusExceptionIfNecessary
public void throwFacebookResponseStatusExceptionIfNecessary(String json, Integer httpStatusCode)
Description copied from interface:FacebookExceptionGenerator
Throws an exception if Facebook returned an error response. Using the Graph API, it's possible to see both the new Graph API-style errors as well as Legacy API-style errors, so we have to handle both here. This method extracts relevant information from the error JSON and throws an exception which encapsulates it for end-user consumption.For Graph API errors:
If the
error
JSON field is present, we've got a response status error for this API call.For Legacy errors (e.g. FQL):
If the
error_code
JSON field is present, we've got a response status error for this API call.- Specified by:
throwFacebookResponseStatusExceptionIfNecessary
in interfaceFacebookExceptionGenerator
- Parameters:
json
- The JSON returned by Facebook in response to an API call.httpStatusCode
- The HTTP status code returned by the server, e.g. 500.
-
createFacebookResponseTypeAndMessageContainer
protected ExceptionInformation createFacebookResponseTypeAndMessageContainer(JsonObject errorObject, Integer httpStatusCode)
-
throwBatchFacebookResponseStatusExceptionIfNecessary
public void throwBatchFacebookResponseStatusExceptionIfNecessary(String json, Integer httpStatusCode)
Description copied from interface:FacebookExceptionGenerator
If theerror
anderror_description
JSON fields are present, we've got a response status error for this batch API call. Extracts relevant information from the JSON and throws an exception which encapsulates it for end-user consumption.- Specified by:
throwBatchFacebookResponseStatusExceptionIfNecessary
in interfaceFacebookExceptionGenerator
- Parameters:
json
- The JSON returned by Facebook in response to a batch API call.httpStatusCode
- The HTTP status code returned by the server, e.g. 500.
-
createGraphFacebookExceptionMapper
protected FacebookExceptionMapper createGraphFacebookExceptionMapper()
Specifies how we map Graph API exception types/messages to real Java exceptions.Uses an instance of
DefaultFacebookExceptionGenerator.DefaultGraphFacebookExceptionMapper
by default.- Returns:
- An instance of the exception mapper we should use.
- Since:
- 1.6
-
skipResponseStatusExceptionParsing
protected void skipResponseStatusExceptionParsing(String json) throws ResponseErrorJsonParsingException
checks if a string may be a json and contains a error string somewhere, this is used for speedup the error parsing- Parameters:
json
-- Throws:
ResponseErrorJsonParsingException
-
silentlyCreateObjectFromString
protected JsonObject silentlyCreateObjectFromString(String json)
create aJsonObject
from String and swallow possible JsonException- Parameters:
json
- the string representation of the json- Returns:
- the JsonObject, may be
null
-
-