Added an exception for error 102: user access token required
authorKai Moritz <kai@juplo.de>
Fri, 15 Jan 2016 14:39:37 +0000 (15:39 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 7 Jun 2016 13:53:10 +0000 (15:53 +0200)
src/main/java/de/juplo/facebook/errors/GraphApiException.java
src/main/java/de/juplo/facebook/errors/UserAccessTokenRequiredException.java [new file with mode: 0644]
src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java

index 45dd38a..a3c3904 100644 (file)
@@ -69,6 +69,7 @@ public class GraphApiException extends OAuth2Exception
       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 (file)
index 0000000..cb91950
--- /dev/null
@@ -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);
+  }
+}
index 9fc7fc3..4d1e636 100644 (file)
@@ -176,6 +176,29 @@ 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("invalid_request", e.getOAuth2ErrorCode());
+      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()
   {