X-Git-Url: https://juplo.de/gitweb/?p=facebook-errors;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Ffacebook%2Fexceptions%2FGraphApiException.java;fp=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Ffacebook%2Fexceptions%2FGraphApiException.java;h=03aa6278dbfe5da76ec07446a0b5ac4c7ff4c3b3;hp=0000000000000000000000000000000000000000;hb=bc0989ddb7bb05e2d95ae4aad4438b4d4806f9dc;hpb=80f6b663c648f011425b521e7c4185128a00149d diff --git a/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java b/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java new file mode 100644 index 0000000..03aa627 --- /dev/null +++ b/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java @@ -0,0 +1,62 @@ +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(); + } +}