190: Access token expired
[facebook-errors] / src / main / java / de / juplo / facebook / errors / GraphApiException.java
index ac57308..1b7eaaa 100644 (file)
@@ -11,6 +11,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
 
 
 
@@ -27,7 +29,9 @@ public class GraphApiException extends RuntimeException
   final static Logger LOG = LoggerFactory.getLogger(GraphApiException.class);
   final static ObjectMapper OBJECT_MAPPER;
 
-  private final FacebookErrorMessage error;
+  public final HttpStatus status;
+  public final HttpHeaders headers;
+  public final FacebookErrorMessage error;
 
 
   static
@@ -39,65 +43,204 @@ public class GraphApiException extends RuntimeException
   }
 
 
-  public static GraphApiException create(InputStream in)
+  public static GraphApiException create(
+      HttpStatus status,
+      HttpHeaders headers,
+      InputStream in
+      )
       throws
         IOException,
         JsonParseException,
         JsonMappingException
   {
-    return create(OBJECT_MAPPER.readValue(in, FacebookErrorMessage.class));
+    return create(status, headers, OBJECT_MAPPER.readValue(in, FacebookErrorMessage.class));
   }
 
-  public static GraphApiException create(byte[] message)
+  public static GraphApiException create(
+      HttpStatus status,
+      HttpHeaders headers,
+      byte[] message
+      )
       throws
         IOException,
         JsonParseException,
         JsonMappingException
   {
-    return create(OBJECT_MAPPER.readValue(message, FacebookErrorMessage.class));
+    return create(status, headers, OBJECT_MAPPER.readValue(message, FacebookErrorMessage.class));
   }
 
-  public static GraphApiException create(FacebookErrorMessage error)
+  public static GraphApiException create(
+      HttpStatus status,
+      HttpHeaders headers,
+      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);
+      case 1:     return new UnknownErrorException(status, headers, error);
+      case 2:     return new UnexpectedErrorException(status, headers, error);
+      case 4:     return new ApplicationRequestLimitReachedException(status, headers, error);
+      case 10:    return new AuthorizationMissingException(status, headers, error);
+      case 12:    return new DeprecatedException(status, headers, error);
+      case 17:    return new AccountRequestLimitReachedException(status, headers, error);
+      case 21:    return new PageMigratedException(status, headers, error);
+      case 32:    return new PageRequestLimitReachedException(status, headers, error);
       // 100..199: graph method errors
-      case 100:   return new UnsupportedGetRequestException(error);
-      case 104:   return new AccessTokenRequiredException(error);
+      case 100:   return new UnsupportedGetRequestException(status, headers, error);
+      case 102:   return new UserAccessTokenRequiredException(status, headers, error);
+      case 104:   return new AccessTokenRequiredException(status, headers, error);
+      case 190:   return new AccessTokenExpiredException(status, headers, error);
       // 200..299: permission errors
-      // 300..399: data editing errors
+      case 200:
+      case 201:
+      case 202:
+      case 203:
+      case 204:
+      case 205:
+      case 206:
+      case 207:
+      case 208:
+      case 209:
+      case 210:
+      case 211:
+      case 212:
+      case 213:
+      case 214:
+      case 215:
+      case 216:
+      case 217:
+      case 218:
+      case 219:
+      case 220:
+      case 221:
+      case 222:
+      case 223:
+      case 224:
+      case 225:
+      case 226:
+      case 227:
+      case 228:
+      case 229:
+      case 230:
+      case 231:
+      case 232:
+      case 233:
+      case 234:
+      case 235:
+      case 236:
+      case 237:
+      case 238:
+      case 239:
+      case 240:
+      case 241:
+      case 242:
+      case 243:
+      case 244:
+      case 245:
+      case 246:
+      case 247:
+      case 248:
+      case 249:
+      case 250:
+      case 251:
+      case 252:
+      case 253:
+      case 254:
+      case 255:
+      case 256:
+      case 257:
+      case 258:
+      case 259:
+      case 260:
+      case 261:
+      case 262:
+      case 263:
+      case 264:
+      case 265:
+      case 266:
+      case 267:
+      case 268:
+      case 269:
+      case 270:
+      case 271:
+      case 272:
+      case 273:
+      case 274:
+      case 275:
+      case 276:
+      case 277:
+      case 278:
+      case 279:
+      case 280:
+      case 281:
+      case 282:
+      case 283:
+      case 284:
+      case 285:
+      case 286:
+      case 287:
+      case 288:
+      case 289:
+      case 290:
+      case 291:
+      case 292:
+      case 293:
+      case 294:
+      case 295:
+      case 296:
+      case 297:
+      case 298:
+      case 299:   return new AuthorizationMissingException(status, headers, error);
+      // 200..299: permission errors
+      // 300..399: data editing errors ?
+      case 341:   return new TemporaryRateLimitExceededException(status, headers, error);
       // 400..449: authentication error
       // 450..499: session errors
-      // 500..599: application messaging errors
+      // 500..599: application messaging errors ?
+      case 506:   return new MultipleConcurrentPostsException(status, headers, error);
       // 600..699: FQL errors
-      case 613:   return new RateExceededException(error);
+      case 613:   return new RateLimitExceededException(status, headers, 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
-      case 2200:  return new CallbackVerificationFailedException(error);
+      case 1609005: return new LinkPostFailureException(status, headers, error);
+      case 2200:  return new CallbackVerificationFailedException(status, headers, error);
 
       default:
         LOG.info("unmapped error: {}", error);
-        return new UnmappedErrorException(error);
+        return new UnmappedErrorException(status, headers, error);
     }
   }
 
 
-  protected GraphApiException(FacebookErrorMessage error)
+  protected GraphApiException(
+      HttpStatus status,
+      HttpHeaders headers,
+      FacebookErrorMessage error
+      )
   {
     super(error.message);
+    this.status = status;
+    this.headers = headers;
     this.error = error;
   }
 
 
+  public HttpStatus getStatus()
+  {
+    return status;
+  }
+
+  public HttpHeaders getHeaders()
+  {
+    return headers;
+  }
+
   public Type getType()
   {
     return error.type == null ? null : Type.valueOf(error.type);