From 16dada3d8c499862992c1b8472f5cef3355106f1 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Mon, 9 Jul 2018 20:59:34 +0200 Subject: [PATCH] Added/Renamed the exceptions, that are thrown, if the rate-limit is exceeded * Added new exceptions, that were introduced with version 3.0 of the Facebook Graph-API (or maybe with another version since 2.5). * Renamed the exceptions, that handle the rate-limiting, according to the terms used in the current documentation. --- .../AccountRequestLimitReachedException.java | 16 +++++++++ ...plicationRequestLimitReachedException.java | 15 +++++++++ .../CustomRequestLimitReachedException.java | 19 +++++++++++ .../facebook/errors/GraphApiException.java | 7 ++-- .../PageRequestLimitReachedException.java | 16 +++++++++ .../errors/RateLimitExceededException.java | 15 --------- .../errors/TooManyAppCallsException.java | 16 --------- .../errors/TooManyUserCallsException.java | 16 --------- .../errors/GraphApiErrorHandlerTest.java | 33 ++++++++++++++++++- 9 files changed, 102 insertions(+), 51 deletions(-) create mode 100644 src/main/java/de/juplo/facebook/errors/AccountRequestLimitReachedException.java create mode 100644 src/main/java/de/juplo/facebook/errors/ApplicationRequestLimitReachedException.java create mode 100644 src/main/java/de/juplo/facebook/errors/CustomRequestLimitReachedException.java create mode 100644 src/main/java/de/juplo/facebook/errors/PageRequestLimitReachedException.java delete mode 100644 src/main/java/de/juplo/facebook/errors/RateLimitExceededException.java delete mode 100644 src/main/java/de/juplo/facebook/errors/TooManyAppCallsException.java delete mode 100644 src/main/java/de/juplo/facebook/errors/TooManyUserCallsException.java diff --git a/src/main/java/de/juplo/facebook/errors/AccountRequestLimitReachedException.java b/src/main/java/de/juplo/facebook/errors/AccountRequestLimitReachedException.java new file mode 100644 index 0000000..ab0af95 --- /dev/null +++ b/src/main/java/de/juplo/facebook/errors/AccountRequestLimitReachedException.java @@ -0,0 +1,16 @@ +package de.juplo.facebook.errors; + + + +/** + * 17: Account request limit reached. + * @author Kai Moritz + * @see https://developers.facebook.com/docs/graph-api/using-graph-api/#errors + */ +public class AccountRequestLimitReachedException extends OAuthException +{ + protected AccountRequestLimitReachedException(FacebookErrorMessage error) + { + super(error); + } +} diff --git a/src/main/java/de/juplo/facebook/errors/ApplicationRequestLimitReachedException.java b/src/main/java/de/juplo/facebook/errors/ApplicationRequestLimitReachedException.java new file mode 100644 index 0000000..6a2196c --- /dev/null +++ b/src/main/java/de/juplo/facebook/errors/ApplicationRequestLimitReachedException.java @@ -0,0 +1,15 @@ +package de.juplo.facebook.errors; + + + +/** + * 4: (#4) Application request limit reached. + * @author Kai Moritz + */ +public class ApplicationRequestLimitReachedException extends OAuthException +{ + protected ApplicationRequestLimitReachedException(FacebookErrorMessage error) + { + super(error); + } +} diff --git a/src/main/java/de/juplo/facebook/errors/CustomRequestLimitReachedException.java b/src/main/java/de/juplo/facebook/errors/CustomRequestLimitReachedException.java new file mode 100644 index 0000000..7beaea2 --- /dev/null +++ b/src/main/java/de/juplo/facebook/errors/CustomRequestLimitReachedException.java @@ -0,0 +1,19 @@ +package de.juplo.facebook.errors; + + + +/** + * 613: Calls to stream have exceeded the rate of 600 calls per 600 seconds. + * Taken from https://developers.facebook.com/docs/graph-api/advanced/rate-limiting?locale=en_US#faq + * I'm seeing Error Code 613, what do I do? + * If your error response contains error_subcode 1996, Facebook has noticed inconsistent behavior in the API request volume of your app. If you have made any recent changes that affect the number of API requests, you may be encountering this error. + * If you do not see the subcode, your app is exceeding a custom rate limit. Please contact your Partner Manager for help resolving this issue. + * @author Kai Moritz + */ +public class CustomRequestLimitReachedException extends OAuthException +{ + protected CustomRequestLimitReachedException(FacebookErrorMessage error) + { + super(error); + } +} diff --git a/src/main/java/de/juplo/facebook/errors/GraphApiException.java b/src/main/java/de/juplo/facebook/errors/GraphApiException.java index 53f075e..53bbbe6 100644 --- a/src/main/java/de/juplo/facebook/errors/GraphApiException.java +++ b/src/main/java/de/juplo/facebook/errors/GraphApiException.java @@ -65,11 +65,12 @@ 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 4: return new ApplicationRequestLimitReachedException(error); case 10: return new AuthorizationMissingException(error); case 12: return new DeprecatedException(error); - case 17: return new TooManyUserCallsException(error); + case 17: return new AccountRequestLimitReachedException(error); case 21: return new PageMigratedException(error); + case 32: return new PageRequestLimitReachedException(error); // 100..199: graph method errors case 100: return new UnsupportedGetRequestException(error); case 102: return new UserAccessTokenRequiredException(error); @@ -183,7 +184,7 @@ public class GraphApiException extends RuntimeException // 500..599: application messaging errors ? case 506: return new MultipleConcurrentPostsException(error); // 600..699: FQL errors - case 613: return new RateLimitExceededException(error); + case 613: return new CustomRequestLimitReachedException(error); // 700..749: ref errors // 750..799: application integration errors // 900..949: application information errors diff --git a/src/main/java/de/juplo/facebook/errors/PageRequestLimitReachedException.java b/src/main/java/de/juplo/facebook/errors/PageRequestLimitReachedException.java new file mode 100644 index 0000000..e4ee191 --- /dev/null +++ b/src/main/java/de/juplo/facebook/errors/PageRequestLimitReachedException.java @@ -0,0 +1,16 @@ +package de.juplo.facebook.errors; + + + +/** + * 32: Account request limit reached. + * @author Kai Moritz + * @see https://developers.facebook.com/docs/graph-api/using-graph-api/#errors + */ +public class PageRequestLimitReachedException extends OAuthException +{ + protected PageRequestLimitReachedException(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 deleted file mode 100644 index 793e219..0000000 --- a/src/main/java/de/juplo/facebook/errors/RateLimitExceededException.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 RateLimitExceededException extends OAuthException -{ - protected RateLimitExceededException(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 deleted file mode 100644 index 4999121..0000000 --- a/src/main/java/de/juplo/facebook/errors/TooManyAppCallsException.java +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index c8ded4d..0000000 --- a/src/main/java/de/juplo/facebook/errors/TooManyUserCallsException.java +++ /dev/null @@ -1,16 +0,0 @@ -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 65149d5..185fd2b 100644 --- a/src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java +++ b/src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java @@ -88,6 +88,37 @@ public class GraphApiErrorHandlerTest } } + @Test + public void testError4() + { + log.info("testError4"); + + + requestFactory.setBody( + "{\n" + + " \"error\": {\n" + + " \"code\": 4, \n" + + " \"fbtrace_id\": \"HZRM6BTMu+D\", \n" + + " \"is_transient\": true, \n" + + " \"message\": \"(#4) Application request limit reached\", \n" + + " \"type\": \"OAuthException\"\n" + + " }\n" + + "}\n"); + + try + { + clientTemplate.getForObject("ANY", SOME.class); + fail("The expected exception was not thrown"); + } + catch(ApplicationRequestLimitReachedException e) + { + log.debug("{}", e.toString()); + assertEquals(new Integer(4), e.getCode()); + assertEquals("(#4) Application request limit reached", e.getMessage()); + assertEquals(Type.OAuthException, e.getType()); + } + } + @Test public void testError12() { @@ -244,7 +275,7 @@ public class GraphApiErrorHandlerTest clientTemplate.getForObject("ANY", SOME.class); fail("The expected exception was not thrown"); } - catch(RateLimitExceededException e) + catch(CustomRequestLimitReachedException e) { log.debug("{}", e.toString()); assertEquals(new Integer(613), e.getCode()); -- 2.20.1