From e3b130e04e4e89a08e203185ba9ae7e6c1f350d8 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Wed, 20 Nov 2019 23:09:52 +0100 Subject: [PATCH] 200: The user hasn't authorized the application to perform this action --- ...plicationNotAuthorizedByUserException.java | 24 ++++++++++++++++ .../facebook/errors/GraphApiException.java | 2 +- .../errors/GraphApiErrorHandlerTest.java | 28 +++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/juplo/facebook/errors/ApplicationNotAuthorizedByUserException.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 index 0000000..05eae6f --- /dev/null +++ b/src/main/java/de/juplo/facebook/errors/ApplicationNotAuthorizedByUserException.java @@ -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); + } +} diff --git a/src/main/java/de/juplo/facebook/errors/GraphApiException.java b/src/main/java/de/juplo/facebook/errors/GraphApiException.java index a781c3b..710d662 100644 --- a/src/main/java/de/juplo/facebook/errors/GraphApiException.java +++ b/src/main/java/de/juplo/facebook/errors/GraphApiException.java @@ -91,7 +91,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: diff --git a/src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java b/src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java index c9a53cd..c171956 100644 --- a/src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java +++ b/src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java @@ -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() { -- 2.20.1