From 8c6762b8a2179257b9f45364637bf5ebbcb19325 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 15 Jan 2016 15:39:37 +0100 Subject: [PATCH] Added an exception for error 102: user access token required --- .../facebook/errors/GraphApiException.java | 1 + .../UserAccessTokenRequiredException.java | 15 +++++++++++++ .../errors/GraphApiErrorHandlerTest.java | 22 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 src/main/java/de/juplo/facebook/errors/UserAccessTokenRequiredException.java diff --git a/src/main/java/de/juplo/facebook/errors/GraphApiException.java b/src/main/java/de/juplo/facebook/errors/GraphApiException.java index ac57308..373a9d5 100644 --- a/src/main/java/de/juplo/facebook/errors/GraphApiException.java +++ b/src/main/java/de/juplo/facebook/errors/GraphApiException.java @@ -68,6 +68,7 @@ public class GraphApiException extends RuntimeException 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 diff --git a/src/main/java/de/juplo/facebook/errors/UserAccessTokenRequiredException.java b/src/main/java/de/juplo/facebook/errors/UserAccessTokenRequiredException.java new file mode 100644 index 0000000..cb91950 --- /dev/null +++ b/src/main/java/de/juplo/facebook/errors/UserAccessTokenRequiredException.java @@ -0,0 +1,15 @@ +package de.juplo.facebook.errors; + + + +/** + * A user access token is required to request this resource. + * @author Kai Moritz + */ +public class UserAccessTokenRequiredException extends OAuthException +{ + public UserAccessTokenRequiredException(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 9a5d302..f8cb142 100644 --- a/src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java +++ b/src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java @@ -148,6 +148,28 @@ public class GraphApiErrorHandlerTest } } + @Test + public void testError102() + { + log.info("testError102"); + + requestFactory.setBody("{\"error\":{\"message\":\"A user access token is required to request this resource.\",\"type\":\"OAuthException\",\"code\":102,\"fbtrace_id\":\"DhdMyf23Ki7\"}}"); + + try + { + clientTemplate.getForObject("ANY", SOME.class); + fail("The expected exception was not thrown"); + } + catch(UserAccessTokenRequiredException e) + { + log.debug("{}", e.toString()); + assertEquals(new Integer(102), e.getCode()); + assertEquals("A user access token is required to request this resource.", e.getMessage()); + assertEquals(Type.OAuthException, e.getType()); + assertEquals("DhdMyf23Ki7", e.getTraceId()); + } + } + @Test public void testError104() { -- 2.20.1