+ OBJECT_MAPPER = new ObjectMapper();
+ 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);
+ }
+
+
+ public static GraphApiException create(InputStream in)
+ throws
+ IOException,
+ JsonParseException,
+ JsonMappingException
+ {
+ return create(OBJECT_MAPPER.readValue(in, FacebookErrorMessage.class));
+ }
+
+ public static GraphApiException create(byte[] message)
+ throws
+ IOException,
+ JsonParseException,
+ JsonMappingException
+ {
+ return create(OBJECT_MAPPER.readValue(message, FacebookErrorMessage.class));
+ }
+
+ public static GraphApiException create(FacebookErrorMessage error)
+ {
+ // see: http://fbdevwiki.com/wiki/Error_codes
+ switch(error.code)
+ {
+ // 1..99: general errors
+ case 1: return new UnknownErrorException(error);
+ case 2: return new UnexpectedErrorException(error);
+ case 21: return new PageMigratedException(error);
+ // 100..199: graph method errors
+ case 100: return new UnsupportedGetRequestException(error);
+ // 200..299: permission errors
+ // 300..399: data editing errors
+ // 400..449: authentication error
+ // 450..499: session errors
+ // 500..599: application messaging errors
+ // 600..699: FQL errors
+ case 613: return new RateExceededException(error);
+ // 700..749: ref errors
+ // 750..799: application integration errors
+ // 900..949: application information errors
+ // 950..999: batch api errors
+ // 1000..1099: event api errors
+ // 1100..1199: live-message errors
+
+ default: return new UnmappedErrorException(error);
+ }
+ }
+
+
+ protected GraphApiException(FacebookErrorMessage error)
+ {
+ super(error.message);
+ this.error = error;