Implemented new exception AccessTokenRequiredException
authorKai Moritz <kai@juplo.de>
Sat, 7 Nov 2015 18:56:39 +0000 (19:56 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 10 Nov 2015 14:51:19 +0000 (15:51 +0100)
src/main/java/de/juplo/facebook/exceptions/AccessTokenRequiredException.java [new file with mode: 0644]
src/main/java/de/juplo/facebook/exceptions/GraphApiException.java
src/test/java/de/juplo/facebook/client/GraphApiErrorHandlerTest.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 (file)
index 0000000..2ac5e2f
--- /dev/null
@@ -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);
+  }
+}
index ee62a93..807c8b3 100644 (file)
@@ -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
index 15dfba3..3917404 100644 (file)
@@ -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()
   {