190: Access token expired
authorKai Moritz <kai@juplo.de>
Tue, 29 Oct 2019 18:18:53 +0000 (19:18 +0100)
committerKai Moritz <kai@jupl.de>
Fri, 22 Nov 2019 06:39:44 +0000 (07:39 +0100)
src/main/java/de/juplo/facebook/errors/AccessTokenExpiredException.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/AccessTokenExpiredException.java b/src/main/java/de/juplo/facebook/errors/AccessTokenExpiredException.java
new file mode 100644 (file)
index 0000000..dfe53f5
--- /dev/null
@@ -0,0 +1,26 @@
+package de.juplo.facebook.errors;
+
+
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+
+
+
+
+/**
+ * 190: Bad signature (access token expired!).
+ * As of Octobre 2019 the {@link https://developers.facebook.com/docs/graph-api/using-graph-api/error-handling/ Documentation }
+ * says "Access token has expired. Get a new access token." for code 190.
+ * @author Kai Moritz
+ */
+public class AccessTokenExpiredException extends OAuthException
+{
+  protected AccessTokenExpiredException(
+      HttpStatus status,
+      HttpHeaders headers,
+      FacebookErrorMessage error
+      )
+  {
+    super(status, headers, error);
+  }
+}
index 31c23dc..1b7eaaa 100644 (file)
@@ -91,6 +91,7 @@ public class GraphApiException extends RuntimeException
       case 100:   return new UnsupportedGetRequestException(status, headers, error);
       case 102:   return new UserAccessTokenRequiredException(status, headers, error);
       case 104:   return new AccessTokenRequiredException(status, headers, error);
+      case 190:   return new AccessTokenExpiredException(status, headers, error);
       // 200..299: permission errors
       case 200:
       case 201:
index 2e03df7..c9a53cd 100644 (file)
@@ -254,6 +254,28 @@ public class GraphApiErrorHandlerTest
     }
   }
 
+  @Test
+  public void testError190()
+  {
+    log.info("testError190");
+
+    requestFactory.setBody("{\"error\":{\"message\":\"Bad signature\",\"type\":\"OAuthException\",\"code\":190,\"fbtrace_id\":\"Ay2OYQrINbXOCfQpBvoxDIw\"}}");
+
+    try
+    {
+      clientTemplate.getForObject("ANY", SOME.class);
+      fail("The expected exception was not thrown");
+    }
+    catch(AccessTokenExpiredException e)
+    {
+      log.debug("{}", e.toString());
+      assertEquals(new Integer(190), e.getCode());
+      assertEquals("Bad signature", e.getMessage());
+      assertEquals(Type.OAuthException, e.getType());
+      assertEquals("Ay2OYQrINbXOCfQpBvoxDIw", e.getTraceId());
+    }
+  }
+
   @Test
   public void testError613()
   {