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