X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Ffacebook%2Fexceptions%2FGraphApiException.java;h=a01a9e13b6667615830b4434447a86dc19d72032;hb=f20abf96293927105ab0cd0033d34f1f821bde46;hp=ee62a930654c87519db35bba02cb9671e7d6a1dc;hpb=f3f458945a13d8d86d629711318ed7a6a2115233;p=facebook-errors diff --git a/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java b/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java index ee62a93..a01a9e1 100644 --- a/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java +++ b/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java @@ -5,12 +5,16 @@ 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.core.SerializableString; +import com.fasterxml.jackson.core.io.CharacterEscapes; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; +import java.nio.ByteBuffer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.oauth2.common.exceptions.OAuth2Exception; @@ -22,6 +26,9 @@ import org.springframework.security.oauth2.common.exceptions.OAuth2Exception; */ public class GraphApiException extends OAuth2Exception { + public enum Type { OAuthException, GraphMethodException } + + final static Logger LOG = LoggerFactory.getLogger(GraphApiException.class); final static ObjectMapper OBJECT_MAPPER; @@ -34,6 +41,7 @@ public class GraphApiException extends OAuth2Exception OBJECT_MAPPER.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); OBJECT_MAPPER.configure(DeserializationFeature.ACCEPT_FLOAT_AS_INT, false); OBJECT_MAPPER.configure(SerializationFeature.WRAP_ROOT_VALUE, true); + OBJECT_MAPPER.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); } @@ -66,6 +74,7 @@ public class GraphApiException extends OAuth2Exception case 21: return new PageMigratedException(error); // 100..199: graph method errors case 100: return new UnsupportedGetRequestException(error); + case 104: return new AccessTokenRequiredException(error); // 200..299: permission errors // 300..399: data editing errors // 400..449: authentication error @@ -79,6 +88,7 @@ public class GraphApiException extends OAuth2Exception // 950..999: batch api errors // 1000..1099: event api errors // 1100..1199: live-message errors + case 2200: return new CallbackVerificationFailedException(error); default: LOG.info("unmapped error: {}", error); @@ -94,9 +104,9 @@ public class GraphApiException extends OAuth2Exception } - public String getType() + public Type getType() { - return error.type; + return error.type == null ? null : Type.valueOf(error.type); } public Integer getCode() @@ -165,4 +175,115 @@ public class GraphApiException extends OAuth2Exception @JsonProperty("fbtrace_id") String traceId; } + + public static class CustomCharacterEscapes extends CharacterEscapes + { + private final int[] _asciiEscapes; + + + public CustomCharacterEscapes() + { + _asciiEscapes = standardAsciiEscapesForJSON(); + _asciiEscapes['/'] = CharacterEscapes.ESCAPE_CUSTOM; + } + + + @Override + public int[] getEscapeCodesForAscii() + { + return _asciiEscapes; + } + + @Override + public SerializableString getEscapeSequence(int i) + { + if(i == '/') + { + return new SerializableString() + { + @Override + public String getValue() + { + return "\\/"; + } + + @Override + public int charLength() + { + return 2; + } + + @Override + public char[] asQuotedChars() + { + return new char[]{'\\','/'}; + } + + @Override + public byte[] asUnquotedUTF8() + { + return new byte[]{'\\','/'}; + } + + @Override + public byte[] asQuotedUTF8() + { + return new byte[]{'\\','/'}; + } + + @Override + public int appendQuotedUTF8(byte[] buffer, int offset) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public int appendQuoted(char[] buffer, int offset) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public int appendUnquotedUTF8(byte[] buffer, int offset) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public int appendUnquoted(char[] buffer, int offset) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public int writeQuotedUTF8(OutputStream out) throws IOException + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public int writeUnquotedUTF8(OutputStream out) throws IOException + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public int putQuotedUTF8(ByteBuffer buffer) throws IOException + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public int putUnquotedUTF8(ByteBuffer out) throws IOException + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + }; + } + else + { + return null; + } + } + } }