From 24361a39e7ec511fd621c0fee59263e70ab0c2c9 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 7 Jun 2016 15:03:31 +0200 Subject: [PATCH] Refactoring: moved FacebookErrorMessage in its own file/class --- .../AccessTokenRequiredException.java | 3 -- .../exceptions/FacebookErrorMessage.java | 42 +++++++++++++++++++ .../exceptions/GraphApiException.java | 29 ------------- .../facebook/exceptions/OAuthException.java | 3 -- .../exceptions/UnexpectedErrorException.java | 3 -- .../exceptions/UnknownErrorException.java | 3 -- .../FacebookErrorMessageMappingTest.java | 4 +- 7 files changed, 45 insertions(+), 42 deletions(-) create mode 100644 src/main/java/de/juplo/facebook/exceptions/FacebookErrorMessage.java diff --git a/src/main/java/de/juplo/facebook/exceptions/AccessTokenRequiredException.java b/src/main/java/de/juplo/facebook/exceptions/AccessTokenRequiredException.java index 2ac5e2f..c55fc36 100644 --- a/src/main/java/de/juplo/facebook/exceptions/AccessTokenRequiredException.java +++ b/src/main/java/de/juplo/facebook/exceptions/AccessTokenRequiredException.java @@ -1,9 +1,6 @@ package de.juplo.facebook.exceptions; -import de.juplo.facebook.exceptions.GraphApiException.FacebookErrorMessage; - - /** * 104: An access token is required to request this resource. diff --git a/src/main/java/de/juplo/facebook/exceptions/FacebookErrorMessage.java b/src/main/java/de/juplo/facebook/exceptions/FacebookErrorMessage.java new file mode 100644 index 0000000..a1bd4b3 --- /dev/null +++ b/src/main/java/de/juplo/facebook/exceptions/FacebookErrorMessage.java @@ -0,0 +1,42 @@ +package de.juplo.facebook.exceptions; + + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.annotation.JsonRootName; + + + +/** + * This class represents an error message from the Graph-API + * + * @see Graph-API Documentation + * @author Kai Moritz + */ +@JsonRootName("error") +@JsonPropertyOrder({ + "message", + "type", + "code", + "error_subcode", + "error_user_title", + "error_user_msg", + "fbtrace_id" + }) +public class FacebookErrorMessage +{ + @JsonProperty("message") + String message; + @JsonProperty("type") + String type; + @JsonProperty("code") + Integer code; + @JsonProperty("error_subcode") + Integer subCode; + @JsonProperty("error_user_title") + String userTitle; + @JsonProperty("error_user_msg") + String userMessage; + @JsonProperty("fbtrace_id") + String traceId; +} diff --git a/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java b/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java index 9379abe..375c5b8 100644 --- a/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java +++ b/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java @@ -1,8 +1,5 @@ package de.juplo.facebook.exceptions; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.annotation.JsonRootName; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -144,30 +141,4 @@ public class GraphApiException extends OAuth2Exception return e.getMessage(); } } - - - /** - * This class represents an error message from the Graph-API - * - * @see Graph-API Documentation - */ - @JsonRootName("error") - @JsonPropertyOrder({ "message", "type", "code", "error_subcode", "error_user_title", "error_user_msg", "fbtrace_id" }) - public static class FacebookErrorMessage - { - @JsonProperty("message") - String message; - @JsonProperty("type") - String type; - @JsonProperty("code") - Integer code; - @JsonProperty("error_subcode") - Integer subCode; - @JsonProperty("error_user_title") - String userTitle; - @JsonProperty("error_user_msg") - String userMessage; - @JsonProperty("fbtrace_id") - String traceId; - } } diff --git a/src/main/java/de/juplo/facebook/exceptions/OAuthException.java b/src/main/java/de/juplo/facebook/exceptions/OAuthException.java index e8fd312..2235dde 100644 --- a/src/main/java/de/juplo/facebook/exceptions/OAuthException.java +++ b/src/main/java/de/juplo/facebook/exceptions/OAuthException.java @@ -1,9 +1,6 @@ package de.juplo.facebook.exceptions; -import de.juplo.facebook.exceptions.GraphApiException.FacebookErrorMessage; - - /** * Baseclass for exceptions of type {@code OAuthException}. diff --git a/src/main/java/de/juplo/facebook/exceptions/UnexpectedErrorException.java b/src/main/java/de/juplo/facebook/exceptions/UnexpectedErrorException.java index 6d7369b..c639c26 100644 --- a/src/main/java/de/juplo/facebook/exceptions/UnexpectedErrorException.java +++ b/src/main/java/de/juplo/facebook/exceptions/UnexpectedErrorException.java @@ -1,9 +1,6 @@ package de.juplo.facebook.exceptions; -import de.juplo.facebook.exceptions.GraphApiException.FacebookErrorMessage; - - /** * 2: An unexpected error has occurred. diff --git a/src/main/java/de/juplo/facebook/exceptions/UnknownErrorException.java b/src/main/java/de/juplo/facebook/exceptions/UnknownErrorException.java index c281f09..b38341a 100644 --- a/src/main/java/de/juplo/facebook/exceptions/UnknownErrorException.java +++ b/src/main/java/de/juplo/facebook/exceptions/UnknownErrorException.java @@ -1,9 +1,6 @@ package de.juplo.facebook.exceptions; -import de.juplo.facebook.exceptions.GraphApiException.FacebookErrorMessage; - - /** * 1: An unknown error has occurred. diff --git a/src/test/java/de/juplo/facebook/exceptions/FacebookErrorMessageMappingTest.java b/src/test/java/de/juplo/facebook/exceptions/FacebookErrorMessageMappingTest.java index 3d672a4..ed1cba8 100644 --- a/src/test/java/de/juplo/facebook/exceptions/FacebookErrorMessageMappingTest.java +++ b/src/test/java/de/juplo/facebook/exceptions/FacebookErrorMessageMappingTest.java @@ -1,13 +1,15 @@ package de.juplo.facebook.exceptions; + import com.fasterxml.jackson.core.JsonProcessingException; -import de.juplo.facebook.exceptions.GraphApiException.FacebookErrorMessage; import static de.juplo.facebook.exceptions.GraphApiException.OBJECT_MAPPER; import de.juplo.facebook.exceptions.GraphApiException.Type; import java.io.IOException; import org.junit.Test; import static org.junit.Assert.assertEquals; + + /** * @author Kai Moritz */ -- 2.20.1