Refactoring: renamed package de.juplo.facebook.exceptions to errors
[facebook-utils] / src / main / java / de / juplo / facebook / errors / PageMigratedException.java
diff --git a/src/main/java/de/juplo/facebook/errors/PageMigratedException.java b/src/main/java/de/juplo/facebook/errors/PageMigratedException.java
new file mode 100644 (file)
index 0000000..c339d83
--- /dev/null
@@ -0,0 +1,45 @@
+package de.juplo.facebook.errors;
+
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+
+
+/**
+ * 21: Page ID (XXX) was migrated to page ID (YYY).
+ * @author Kai Moritz
+ */
+public class PageMigratedException extends OAuthException
+{
+  private final static Pattern pattern =
+      Pattern.compile("Page ID ([0-9]+) was migrated to page ID ([0-9]+)");
+
+  private final Long oldId, newId;
+
+
+  protected PageMigratedException(FacebookErrorMessage error)
+  {
+    super(error);
+    Matcher matcher = pattern.matcher(error.message);
+    if (!matcher.find())
+    {
+      String warning = "Could not parse migration-error: " + error.message;
+      LOG.error(warning);
+      throw new RuntimeException(warning);
+    }
+    oldId = Long.parseLong(matcher.group(1));
+    newId = Long.parseLong(matcher.group(2));
+  }
+
+
+  public Long getOldId()
+  {
+    return oldId;
+  }
+
+  public Long getNewId()
+  {
+    return newId;
+  }
+}