--- /dev/null
+package de.juplo.facebook.exceptions;
+
+import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
+
+/**
+ * Base exception for Facebook Graph-Api exceptions.
+ *
+ * @author Kai Moritz
+ */
+@org.codehaus.jackson.map.annotate.JsonDeserialize(using = GraphApiExceptionJackson1Deserializer.class)
+@com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = GraphApiExceptionJackson2Deserializer.class)
+public class GraphApiException extends OAuth2Exception
+{
+ private final String type;
+ private final int code;
+
+ private int httpErrorCode;
+
+
+ public GraphApiException(String message, String type, int code)
+ {
+ super(message);
+ this.type = type;
+ this.code = code;
+ }
+
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public int getCode()
+ {
+ return code;
+ }
+
+ @Override
+ public int getHttpErrorCode()
+ {
+ return httpErrorCode == 0 ? super.getHttpErrorCode() : httpErrorCode;
+ }
+
+ public void setHttpErrorCode(int httpErrorCode)
+ {
+ this.httpErrorCode = httpErrorCode;
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("{error:{\"message\":\"");
+ builder.append(getMessage().replaceAll("\"", "\\\""));
+ builder.append("\",\"type\":");
+ builder.append(type.replaceAll("\"", "\\\""));
+ builder.append("\",\"code\":");
+ builder.append(code);
+ builder.append("}}");
+ return builder.toString();
+ }
+}