package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* 104: An access token is required to request this resource.
*/
public class AccessTokenRequiredException extends OAuthException
{
- protected AccessTokenRequiredException(FacebookErrorMessage error)
+ protected AccessTokenRequiredException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* 17: Account request limit reached.
*/
public class AccountRequestLimitReachedException extends OAuthException
{
- protected AccountRequestLimitReachedException(FacebookErrorMessage error)
+ protected AccountRequestLimitReachedException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* 4: (#4) Application request limit reached.
*/
public class ApplicationRequestLimitReachedException extends OAuthException
{
- protected ApplicationRequestLimitReachedException(FacebookErrorMessage error)
+ protected ApplicationRequestLimitReachedException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* 10: Authorization declined / not granted
*/
public class AuthorizationMissingException extends OAuthException
{
- protected AuthorizationMissingException(FacebookErrorMessage error)
+ protected AuthorizationMissingException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* 2200: Callback verification failed.
* @author Kai Moritz
*/
public class CallbackVerificationFailedException extends OAuthException
{
- protected CallbackVerificationFailedException(FacebookErrorMessage error)
+ protected CallbackVerificationFailedException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* 613: Calls to stream have exceeded the rate of 600 calls per 600 seconds.
*/
public class CustomRequestLimitReachedException extends OAuthException
{
- protected CustomRequestLimitReachedException(FacebookErrorMessage error)
+ protected CustomRequestLimitReachedException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* 12: XYZ field is deprecated for versions vZ.Z and higher
*/
public class DeprecatedException extends OAuthException
{
- protected DeprecatedException(FacebookErrorMessage error)
+ protected DeprecatedException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
try
{
- error = GraphApiException.create(body);
+ error = GraphApiException.create(response.getStatusCode(), response.getHeaders(), body);
if (LOG.isInfoEnabled())
LOG.info("error-response: {}", new String(body, Charset.forName("UTF-8")));
}
import java.io.InputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
final static Logger LOG = LoggerFactory.getLogger(GraphApiException.class);
final static ObjectMapper OBJECT_MAPPER;
- private final FacebookErrorMessage error;
+ public final HttpStatus status;
+ public final HttpHeaders headers;
+ public final FacebookErrorMessage error;
static
}
- public static GraphApiException create(InputStream in)
+ public static GraphApiException create(
+ HttpStatus status,
+ HttpHeaders headers,
+ InputStream in
+ )
throws
IOException,
JsonParseException,
JsonMappingException
{
- return create(OBJECT_MAPPER.readValue(in, FacebookErrorMessage.class));
+ return create(status, headers, OBJECT_MAPPER.readValue(in, FacebookErrorMessage.class));
}
- public static GraphApiException create(byte[] message)
+ public static GraphApiException create(
+ HttpStatus status,
+ HttpHeaders headers,
+ byte[] message
+ )
throws
IOException,
JsonParseException,
JsonMappingException
{
- return create(OBJECT_MAPPER.readValue(message, FacebookErrorMessage.class));
+ return create(status, headers, OBJECT_MAPPER.readValue(message, FacebookErrorMessage.class));
}
- public static GraphApiException create(FacebookErrorMessage error)
+ public static GraphApiException create(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
// see: http://fbdevwiki.com/wiki/Error_codes
switch(error.code)
{
// 1..99: general errors
- case 1: return new UnknownErrorException(error);
- case 2: return new UnexpectedErrorException(error);
- case 4: return new ApplicationRequestLimitReachedException(error);
- case 10: return new AuthorizationMissingException(error);
- case 12: return new DeprecatedException(error);
- case 17: return new AccountRequestLimitReachedException(error);
- case 21: return new PageMigratedException(error);
- case 32: return new PageRequestLimitReachedException(error);
+ case 1: return new UnknownErrorException(status, headers, error);
+ case 2: return new UnexpectedErrorException(status, headers, error);
+ case 4: return new ApplicationRequestLimitReachedException(status, headers, error);
+ case 10: return new AuthorizationMissingException(status, headers, error);
+ case 12: return new DeprecatedException(status, headers, error);
+ case 17: return new AccountRequestLimitReachedException(status, headers, error);
+ case 21: return new PageMigratedException(status, headers, error);
+ case 32: return new PageRequestLimitReachedException(status, headers, error);
// 100..199: graph method errors
- case 100: return new UnsupportedGetRequestException(error);
- case 102: return new UserAccessTokenRequiredException(error);
- case 104: return new AccessTokenRequiredException(error);
+ case 100: return new UnsupportedGetRequestException(status, headers, error);
+ case 102: return new UserAccessTokenRequiredException(status, headers, error);
+ case 104: return new AccessTokenRequiredException(status, headers, error);
// 200..299: permission errors
case 200:
case 201:
case 296:
case 297:
case 298:
- case 299: return new AuthorizationMissingException(error);
+ case 299: return new AuthorizationMissingException(status, headers, error);
// 200..299: permission errors
// 300..399: data editing errors ?
- case 341: return new TemporaryRateLimitExceededException(error);
+ case 341: return new TemporaryRateLimitExceededException(status, headers, error);
// 400..449: authentication error
// 450..499: session errors
// 500..599: application messaging errors ?
- case 506: return new MultipleConcurrentPostsException(error);
+ case 506: return new MultipleConcurrentPostsException(status, headers, error);
// 600..699: FQL errors
- case 613: return new CustomRequestLimitReachedException(error);
+ case 613: return new CustomRequestLimitReachedException(status, headers, error);
// 700..749: ref errors
// 750..799: application integration errors
// 900..949: application information errors
// 950..999: batch api errors
// 1000..1099: event api errors
// 1100..1199: live-message errors
- case 1609005: return new LinkPostFailureException(error);
- case 2200: return new CallbackVerificationFailedException(error);
+ case 1609005: return new LinkPostFailureException(status, headers, error);
+ case 2200: return new CallbackVerificationFailedException(status, headers, error);
default:
LOG.info("unmapped error: {}", error);
- return new UnmappedErrorException(error);
+ return new UnmappedErrorException(status, headers, error);
}
}
- protected GraphApiException(FacebookErrorMessage error)
+ protected GraphApiException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
super(error.message);
+ this.status = status;
+ this.headers = headers;
this.error = error;
}
+ public HttpStatus getStatus()
+ {
+ return status;
+ }
+
+ public HttpHeaders getHeaders()
+ {
+ return headers;
+ }
+
public Type getType()
{
return error.type == null ? null : Type.valueOf(error.type);
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* Baseclass for exceptions of type {@code GraphMethodException}.
*/
public abstract class GraphMethodException extends GraphApiException
{
- GraphMethodException(FacebookErrorMessage error)
+ GraphMethodException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* 1609005: Failure while posting link (data could not be read from link)
*/
public class LinkPostFailureException extends OAuthException
{
- protected LinkPostFailureException(FacebookErrorMessage error)
+ protected LinkPostFailureException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* 506: Multiple concurrent posts
*/
public class MultipleConcurrentPostsException extends OAuthException
{
- protected MultipleConcurrentPostsException(FacebookErrorMessage error)
+ protected MultipleConcurrentPostsException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.security.oauth2.client.http.OAuth2ErrorHandler;
-import org.springframework.web.client.ResponseErrorHandler;
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* Baseclass for exceptions of type {@code OAuthException}.
*/
public class OAuthException extends GraphApiException
{
- protected OAuthException(FacebookErrorMessage error)
+ protected OAuthException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
private final Long oldId, newId;
- protected PageMigratedException(FacebookErrorMessage error)
+ protected PageMigratedException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
Matcher matcher = pattern.matcher(error.message);
if (!matcher.find())
{
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* 32: Account request limit reached.
*/
public class PageRequestLimitReachedException extends OAuthException
{
- protected PageRequestLimitReachedException(FacebookErrorMessage error)
+ protected PageRequestLimitReachedException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* 341: Temporary rate-limit excession because of server-failure or throtteling
*/
public class TemporaryRateLimitExceededException extends OAuthException
{
- protected TemporaryRateLimitExceededException(FacebookErrorMessage error)
+ protected TemporaryRateLimitExceededException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* 2: An unexpected error has occurred.
*/
public class UnexpectedErrorException extends OAuthException
{
- protected UnexpectedErrorException(FacebookErrorMessage error)
+ protected UnexpectedErrorException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* 1: An unknown error has occurred.
*/
public class UnknownErrorException extends OAuthException
{
- protected UnknownErrorException(FacebookErrorMessage error)
+ protected UnknownErrorException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* Marker class for error-messages, that are not mapped yet.
*/
public class UnmappedErrorException extends GraphApiException
{
- protected UnmappedErrorException(FacebookErrorMessage error)
+ protected UnmappedErrorException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* 100: Unsupported get request.
*/
public class UnsupportedGetRequestException extends GraphMethodException
{
- protected UnsupportedGetRequestException(FacebookErrorMessage error)
+ protected UnsupportedGetRequestException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}
package de.juplo.facebook.errors;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
/**
* A user access token is required to request this resource.
*/
public class UserAccessTokenRequiredException extends OAuthException
{
- public UserAccessTokenRequiredException(FacebookErrorMessage error)
+ public UserAccessTokenRequiredException(
+ HttpStatus status,
+ HttpHeaders headers,
+ FacebookErrorMessage error
+ )
{
- super(error);
+ super(status, headers, error);
}
}