200: The user hasn't authorized the application to perform this action
authorKai Moritz <kai@jupl.de>
Wed, 20 Nov 2019 22:09:52 +0000 (23:09 +0100)
committerKai Moritz <kai@jupl.de>
Wed, 20 Nov 2019 23:30:09 +0000 (00:30 +0100)
src/main/java/de/juplo/facebook/errors/ApplicationNotAuthorizedByUserException.java [new file with mode: 0644]
src/main/java/de/juplo/facebook/errors/GraphApiException.java
src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java

diff --git a/src/main/java/de/juplo/facebook/errors/ApplicationNotAuthorizedByUserException.java b/src/main/java/de/juplo/facebook/errors/ApplicationNotAuthorizedByUserException.java
new file mode 100644 (file)
index 0000000..05eae6f
--- /dev/null
@@ -0,0 +1,24 @@
+package de.juplo.facebook.errors;
+
+
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
+
+/**
+ * 200: (#200) The user hasn't authorized the application to perform this action"
+ * @author Kai Moritz
+ */
+public class ApplicationNotAuthorizedByUserException extends OAuthException
+{
+  protected ApplicationNotAuthorizedByUserException(
+      HttpStatus status,
+      HttpHeaders headers,
+      FacebookErrorMessage error
+      )
+  {
+    super(status, headers, error);
+  }
+}
index 2528e7e..5ec30fa 100644 (file)
@@ -107,7 +107,7 @@ public class GraphApiException extends RuntimeException
       case 104:   return new AccessTokenRequiredException(status, headers, error);
       case 190:   return new AccessTokenExpiredException(status, headers, error);
       // 200..299: permission errors
-      case 200:
+      case 200:   return new ApplicationNotAuthorizedByUserException(status, headers, error);
       case 201:
       case 202:
       case 203:
index c9a53cd..c171956 100644 (file)
@@ -276,6 +276,34 @@ public class GraphApiErrorHandlerTest
     }
   }
 
+  @Test
+  public void testError200()
+  {
+    log.info("testError200");
+
+    requestFactory.setBody("{\n" +
+        "  \"error\": {\n" +
+        "    \"message\": \"(#200) The user hasn't authorized the application to perform this action\",\n" +
+        "    \"type\": \"OAuthException\",\n" +
+        "    \"code\": 200\n" +
+        "  }\n" +
+        "}");
+
+    try
+    {
+      clientTemplate.getForObject("ANY", SOME.class);
+      fail("The expected exception was not thrown");
+    }
+    catch(ApplicationNotAuthorizedByUserException e)
+    {
+      log.debug("{}", e.toString());
+      assertEquals(new Integer(200), e.getCode());
+      assertEquals("(#200) The user hasn't authorized the application to perform this action", e.getMessage());
+      assertEquals(Type.OAuthException, e.getType());
+      assertNull(e.getTraceId());
+    }
+  }
+
   @Test
   public void testError613()
   {