From: Kai Moritz Date: Sun, 12 Jun 2016 15:27:27 +0000 (+0200) Subject: Implemented exceptions for the error-codes, mentioned in the API-docs X-Git-Tag: wip-webclient~67 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=46af5bccb1479603cb793c52cea992991f42325a;p=facebook-errors Implemented exceptions for the error-codes, mentioned in the API-docs --- diff --git a/src/main/java/de/juplo/facebook/errors/AuthorizationMissingException.java b/src/main/java/de/juplo/facebook/errors/AuthorizationMissingException.java new file mode 100644 index 0000000..440684c --- /dev/null +++ b/src/main/java/de/juplo/facebook/errors/AuthorizationMissingException.java @@ -0,0 +1,17 @@ +package de.juplo.facebook.errors; + + + +/** + * 10: Authorization declined / not granted + * 200-299: Authorization declined / not granted (multiple values, according to authorization) + * @author Kai Moritz + * @see https://developers.facebook.com/docs/graph-api/using-graph-api/#errors + */ +public class AuthorizationMissingException extends OAuthException +{ + protected AuthorizationMissingException(FacebookErrorMessage error) + { + super(error); + } +} diff --git a/src/main/java/de/juplo/facebook/errors/FacebookErrorsSpringSocialAutoConfiguration.java b/src/main/java/de/juplo/facebook/errors/FacebookErrorsSpringSocialAutoConfiguration.java index f474be8..49a3101 100644 --- a/src/main/java/de/juplo/facebook/errors/FacebookErrorsSpringSocialAutoConfiguration.java +++ b/src/main/java/de/juplo/facebook/errors/FacebookErrorsSpringSocialAutoConfiguration.java @@ -5,7 +5,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanCreationException; +import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.social.FacebookAutoConfiguration; @@ -89,4 +93,31 @@ public class FacebookErrorsSpringSocialAutoConfiguration } }; } + + @Bean + static public BeanDefinitionRegistryPostProcessor test() + { + return new BeanDefinitionRegistryPostProcessor() + { + @Override + public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException + { + for(String name : registry.getBeanDefinitionNames()) + { + BeanDefinition bean = registry.getBeanDefinition(name); + LOG.info("{}: {} - {} / {}", name, bean.getBeanClassName(), bean.getFactoryBeanName(), bean); + } + } + + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException + { + for(String name : factory.getBeanNamesForType(Facebook.class)) + { + BeanDefinition bean = factory.getBeanDefinition(name); + LOG.info("{}{}", name, factory.isFactoryBean(name) ? " (factory)" : ""); + } + } + }; + } } \ No newline at end of file diff --git a/src/main/java/de/juplo/facebook/errors/GraphApiException.java b/src/main/java/de/juplo/facebook/errors/GraphApiException.java index 373a9d5..9558b9d 100644 --- a/src/main/java/de/juplo/facebook/errors/GraphApiException.java +++ b/src/main/java/de/juplo/facebook/errors/GraphApiException.java @@ -65,24 +65,131 @@ public class GraphApiException extends RuntimeException // 1..99: general errors case 1: return new UnknownErrorException(error); case 2: return new UnexpectedErrorException(error); + case 4: return new TooManyAppCallsException(error); + case 10: return new AuthorizationMissingException(error); + case 17: return new TooManyUserCallsException(error); case 21: return new PageMigratedException(error); // 100..199: graph method errors case 100: return new UnsupportedGetRequestException(error); case 102: return new UserAccessTokenRequiredException(error); case 104: return new AccessTokenRequiredException(error); // 200..299: permission errors - // 300..399: data editing errors + case 200: + case 201: + case 202: + case 203: + case 204: + case 205: + case 206: + case 207: + case 208: + case 209: + case 210: + case 211: + case 212: + case 213: + case 214: + case 215: + case 216: + case 217: + case 218: + case 219: + case 220: + case 221: + case 222: + case 223: + case 224: + case 225: + case 226: + case 227: + case 228: + case 229: + case 230: + case 231: + case 232: + case 233: + case 234: + case 235: + case 236: + case 237: + case 238: + case 239: + case 240: + case 241: + case 242: + case 243: + case 244: + case 245: + case 246: + case 247: + case 248: + case 249: + case 250: + case 251: + case 252: + case 253: + case 254: + case 255: + case 256: + case 257: + case 258: + case 259: + case 260: + case 261: + case 262: + case 263: + case 264: + case 265: + case 266: + case 267: + case 268: + case 269: + case 270: + case 271: + case 272: + case 273: + case 274: + case 275: + case 276: + case 277: + case 278: + case 279: + case 280: + case 281: + case 282: + case 283: + case 284: + case 285: + case 286: + case 287: + case 288: + case 289: + case 290: + case 291: + case 292: + case 293: + case 294: + case 295: + case 296: + case 297: + case 298: + case 299: return new AuthorizationMissingException(error); + // 200..299: permission errors + // 300..399: data editing errors ? + case 341: return new TemporaryRateLimitExceededException(error); // 400..449: authentication error // 450..499: session errors - // 500..599: application messaging errors + // 500..599: application messaging errors ? + case 506: return new MultipleConcurrentPostsException(error); // 600..699: FQL errors - case 613: return new RateExceededException(error); + case 613: return new RateLimitExceededException(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); default: diff --git a/src/main/java/de/juplo/facebook/errors/LinkPostFailureException.java b/src/main/java/de/juplo/facebook/errors/LinkPostFailureException.java new file mode 100644 index 0000000..7169861 --- /dev/null +++ b/src/main/java/de/juplo/facebook/errors/LinkPostFailureException.java @@ -0,0 +1,16 @@ +package de.juplo.facebook.errors; + + + +/** + * 1609005: Failure while posting link (data could not be read from link) + * @author Kai Moritz + * @see https://developers.facebook.com/docs/graph-api/using-graph-api/#errors + */ +public class LinkPostFailureException extends OAuthException +{ + protected LinkPostFailureException(FacebookErrorMessage error) + { + super(error); + } +} diff --git a/src/main/java/de/juplo/facebook/errors/MultipleConcurrentPostsException.java b/src/main/java/de/juplo/facebook/errors/MultipleConcurrentPostsException.java new file mode 100644 index 0000000..b99bed7 --- /dev/null +++ b/src/main/java/de/juplo/facebook/errors/MultipleConcurrentPostsException.java @@ -0,0 +1,16 @@ +package de.juplo.facebook.errors; + + + +/** + * 506: Multiple concurrent posts + * @author Kai Moritz + * @see https://developers.facebook.com/docs/graph-api/using-graph-api/#errors + */ +public class MultipleConcurrentPostsException extends OAuthException +{ + protected MultipleConcurrentPostsException(FacebookErrorMessage error) + { + super(error); + } +} diff --git a/src/main/java/de/juplo/facebook/errors/RateExceededException.java b/src/main/java/de/juplo/facebook/errors/RateExceededException.java deleted file mode 100644 index e57cc45..0000000 --- a/src/main/java/de/juplo/facebook/errors/RateExceededException.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.juplo.facebook.errors; - - - -/** - * 613: Calls to stream have exceeded the rate of 600 calls per 600 seconds. - * @author Kai Moritz - */ -public class RateExceededException extends OAuthException -{ - protected RateExceededException(FacebookErrorMessage error) - { - super(error); - } -} diff --git a/src/main/java/de/juplo/facebook/errors/RateLimitExceededException.java b/src/main/java/de/juplo/facebook/errors/RateLimitExceededException.java new file mode 100644 index 0000000..793e219 --- /dev/null +++ b/src/main/java/de/juplo/facebook/errors/RateLimitExceededException.java @@ -0,0 +1,15 @@ +package de.juplo.facebook.errors; + + + +/** + * 613: Calls to stream have exceeded the rate of 600 calls per 600 seconds. + * @author Kai Moritz + */ +public class RateLimitExceededException extends OAuthException +{ + protected RateLimitExceededException(FacebookErrorMessage error) + { + super(error); + } +} diff --git a/src/main/java/de/juplo/facebook/errors/TemporaryRateLimitExceededException.java b/src/main/java/de/juplo/facebook/errors/TemporaryRateLimitExceededException.java new file mode 100644 index 0000000..0eba617 --- /dev/null +++ b/src/main/java/de/juplo/facebook/errors/TemporaryRateLimitExceededException.java @@ -0,0 +1,16 @@ +package de.juplo.facebook.errors; + + + +/** + * 341: Temporary rate-limit excession because of server-failure or throtteling + * @author Kai Moritz + * @see https://developers.facebook.com/docs/graph-api/using-graph-api/#errors + */ +public class TemporaryRateLimitExceededException extends OAuthException +{ + protected TemporaryRateLimitExceededException(FacebookErrorMessage error) + { + super(error); + } +} diff --git a/src/main/java/de/juplo/facebook/errors/TooManyAppCallsException.java b/src/main/java/de/juplo/facebook/errors/TooManyAppCallsException.java new file mode 100644 index 0000000..4999121 --- /dev/null +++ b/src/main/java/de/juplo/facebook/errors/TooManyAppCallsException.java @@ -0,0 +1,16 @@ +package de.juplo.facebook.errors; + + + +/** + * 4: To many API-calls + * @author Kai Moritz + * @see https://developers.facebook.com/docs/graph-api/using-graph-api/#errors + */ +public class TooManyAppCallsException extends OAuthException +{ + protected TooManyAppCallsException(FacebookErrorMessage error) + { + super(error); + } +} diff --git a/src/main/java/de/juplo/facebook/errors/TooManyUserCallsException.java b/src/main/java/de/juplo/facebook/errors/TooManyUserCallsException.java new file mode 100644 index 0000000..c8ded4d --- /dev/null +++ b/src/main/java/de/juplo/facebook/errors/TooManyUserCallsException.java @@ -0,0 +1,16 @@ +package de.juplo.facebook.errors; + + + +/** + * 17: To many API-usercalls + * @author Kai Moritz + * @see https://developers.facebook.com/docs/graph-api/using-graph-api/#errors + */ +public class TooManyUserCallsException extends OAuthException +{ + protected TooManyUserCallsException(FacebookErrorMessage error) + { + super(error); + } +} diff --git a/src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java b/src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java index f8cb142..37ab056 100644 --- a/src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java +++ b/src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java @@ -213,7 +213,7 @@ public class GraphApiErrorHandlerTest clientTemplate.getForObject("ANY", SOME.class); fail("The expected exception was not thrown"); } - catch(RateExceededException e) + catch(RateLimitExceededException e) { log.debug("{}", e.toString()); assertEquals(new Integer(613), e.getCode());