The exception stores the HttpStatus and HttpHeaders of the failed request
[facebook-errors] / src / main / java / de / juplo / facebook / errors / PageMigratedException.java
1 package de.juplo.facebook.errors;
2
3
4 import java.util.regex.Matcher;
5 import java.util.regex.Pattern;
6 import org.springframework.http.HttpHeaders;
7 import org.springframework.http.HttpStatus;
8
9
10
11 /**
12  * 21: Page ID (XXX) was migrated to page ID (YYY).
13  * @author Kai Moritz
14  */
15 public class PageMigratedException extends OAuthException
16 {
17   private final static Pattern pattern =
18       Pattern.compile("Page ID ([0-9]+) was migrated to page ID ([0-9]+)");
19
20   private final Long oldId, newId;
21
22
23   protected PageMigratedException(
24       HttpStatus status,
25       HttpHeaders headers,
26       FacebookErrorMessage error
27       )
28   {
29     super(status, headers, error);
30     Matcher matcher = pattern.matcher(error.message);
31     if (!matcher.find())
32     {
33       String warning = "Could not parse migration-error: " + error.message;
34       LOG.error(warning);
35       throw new RuntimeException(warning);
36     }
37     oldId = Long.parseLong(matcher.group(1));
38     newId = Long.parseLong(matcher.group(2));
39   }
40
41
42   public Long getOldId()
43   {
44     return oldId;
45   }
46
47   public Long getNewId()
48   {
49     return newId;
50   }
51 }