From 37fdd444eac1df248db4f543ee8fd2623707f955 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 23 Aug 2016 20:26:17 +0200 Subject: [PATCH] Added an exception for error 12: X field is deprecated vor version vY.Z and higher --- pom.xml | 2 +- .../facebook/errors/DeprecatedException.java | 16 ++++++++++ .../facebook/errors/GraphApiException.java | 1 + src/main/resources/META-INF/spring.factories | 4 +-- .../errors/GraphApiErrorHandlerTest.java | 31 +++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/main/java/de/juplo/facebook/errors/DeprecatedException.java diff --git a/pom.xml b/pom.xml index ed54930..42f2841 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 1.3.5.RELEASE + 1.3.7.RELEASE diff --git a/src/main/java/de/juplo/facebook/errors/DeprecatedException.java b/src/main/java/de/juplo/facebook/errors/DeprecatedException.java new file mode 100644 index 0000000..8274cb6 --- /dev/null +++ b/src/main/java/de/juplo/facebook/errors/DeprecatedException.java @@ -0,0 +1,16 @@ +package de.juplo.facebook.errors; + + + +/** + * 12: XYZ field is deprecated for versions vZ.Z and higher + * @author Kai Moritz + * @see https://developers.facebook.com/docs/graph-api/using-graph-api/#errors + */ +public class DeprecatedException extends OAuthException +{ + protected DeprecatedException(FacebookErrorMessage error) + { + super(error); + } +} diff --git a/src/main/java/de/juplo/facebook/errors/GraphApiException.java b/src/main/java/de/juplo/facebook/errors/GraphApiException.java index 9558b9d..53f075e 100644 --- a/src/main/java/de/juplo/facebook/errors/GraphApiException.java +++ b/src/main/java/de/juplo/facebook/errors/GraphApiException.java @@ -67,6 +67,7 @@ public class GraphApiException extends RuntimeException case 2: return new UnexpectedErrorException(error); case 4: return new TooManyAppCallsException(error); case 10: return new AuthorizationMissingException(error); + case 12: return new DeprecatedException(error); case 17: return new TooManyUserCallsException(error); case 21: return new PageMigratedException(error); // 100..199: graph method errors diff --git a/src/main/resources/META-INF/spring.factories b/src/main/resources/META-INF/spring.factories index 96f4bdd..dd02c20 100644 --- a/src/main/resources/META-INF/spring.factories +++ b/src/main/resources/META-INF/spring.factories @@ -1,3 +1,3 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -de.juplo.facebook.errors.SpringSocialAutoConfiguration,\ -de.juplo.facebook.errors.OAuth2AutoConfiguration +de.juplo.facebook.errors.FacebookErrorsSpringSocialAutoConfiguration,\ +de.juplo.facebook.errors.FacebookErrorsOAuth2AutoConfiguration diff --git a/src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java b/src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java index 37ab056..65149d5 100644 --- a/src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java +++ b/src/test/java/de/juplo/facebook/errors/GraphApiErrorHandlerTest.java @@ -88,6 +88,37 @@ public class GraphApiErrorHandlerTest } } + @Test + public void testError12() + { + log.info("testError12"); + + + requestFactory.setBody( + "{\n" + + " \"error\":\n" + + " {\n" + + " \"message\": \"(#12) location field is deprecated for versions v2.5 and higher\",\n" + + " \"type\": \"OAuthException\",\n" + + " \"code\": 12\n," + + " \"fbtrace_id\":\"BoxCYne7GrL\"\n" + + " }\n" + + "}"); + + try + { + clientTemplate.getForObject("ANY", SOME.class); + fail("The expected exception was not thrown"); + } + catch(DeprecatedException e) + { + log.debug("{}", e.toString()); + assertEquals(new Integer(12), e.getCode()); + assertEquals("(#12) location field is deprecated for versions v2.5 and higher", e.getMessage()); + assertEquals(Type.OAuthException, e.getType()); + } + } + @Test public void testError21() { -- 2.20.1