From 8c94038f0ae450c0487867b444485fdb36f7acc7 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 7 Nov 2015 19:56:39 +0100 Subject: [PATCH] Implemented new exception AccessTokenRequiredException --- .../AccessTokenRequiredException.java | 18 ++++++++++++++ .../exceptions/GraphApiException.java | 1 + .../client/GraphApiErrorHandlerTest.java | 24 +++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 src/main/java/de/juplo/facebook/exceptions/AccessTokenRequiredException.java diff --git a/src/main/java/de/juplo/facebook/exceptions/AccessTokenRequiredException.java b/src/main/java/de/juplo/facebook/exceptions/AccessTokenRequiredException.java new file mode 100644 index 0000000..2ac5e2f --- /dev/null +++ b/src/main/java/de/juplo/facebook/exceptions/AccessTokenRequiredException.java @@ -0,0 +1,18 @@ +package de.juplo.facebook.exceptions; + + +import de.juplo.facebook.exceptions.GraphApiException.FacebookErrorMessage; + + + +/** + * 104: An access token is required to request this resource. + * @author Kai Moritz + */ +public class AccessTokenRequiredException extends OAuthException +{ + protected AccessTokenRequiredException(FacebookErrorMessage error) + { + super(error); + } +} diff --git a/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java b/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java index ee62a93..807c8b3 100644 --- a/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java +++ b/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java @@ -66,6 +66,7 @@ public class GraphApiException extends OAuth2Exception case 21: return new PageMigratedException(error); // 100..199: graph method errors case 100: return new UnsupportedGetRequestException(error); + case 104: return new AccessTokenRequiredException(error); // 200..299: permission errors // 300..399: data editing errors // 400..449: authentication error diff --git a/src/test/java/de/juplo/facebook/client/GraphApiErrorHandlerTest.java b/src/test/java/de/juplo/facebook/client/GraphApiErrorHandlerTest.java index 15dfba3..3917404 100644 --- a/src/test/java/de/juplo/facebook/client/GraphApiErrorHandlerTest.java +++ b/src/test/java/de/juplo/facebook/client/GraphApiErrorHandlerTest.java @@ -1,5 +1,6 @@ package de.juplo.facebook.client; +import de.juplo.facebook.exceptions.AccessTokenRequiredException; import de.juplo.facebook.exceptions.UnsupportedGetRequestException; import de.juplo.facebook.exceptions.UnexpectedErrorException; import de.juplo.facebook.exceptions.RateExceededException; @@ -179,6 +180,29 @@ public class GraphApiErrorHandlerTest } } + @Test + public void testError104() + { + log.info("testError104"); + + requestFactory.setBody("{\"error\":{\"message\":\"An access token is required to request this resource.\",\"type\":\"OAuthException\",\"code\":104,\"fbtrace_id\":\"E2Jjkj5++LL\"}}"); + + try + { + clientTemplate.getForObject("ANY", SOME.class); + fail("The expected exception was not thrown"); + } + catch(AccessTokenRequiredException e) + { + log.debug("{}", e.toString()); + assertEquals("invalid_request", e.getOAuth2ErrorCode()); + assertEquals(new Integer(104), e.getCode()); + assertEquals("An access token is required to request this resource.", e.getMessage()); + assertEquals("OAuthException", e.getType()); + assertEquals("E2Jjkj5++LL", e.getTraceId()); + } + } + @Test public void testError613() { -- 2.20.1