     func application(application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool {
         return true
     }
+
+    // MARK: - Private methods
+
+    private func handleAPIError(error: NSError?) {
+        if error == nil {
+            return
+        }
+
+        if let tabBarController = self.window?.rootViewController as? UITabBarController {
+            if let navVC = tabBarController.selectedViewController as? UINavigationController {
+                if error!.domain == OAuth2Router.APIErrorDomain && error!.code == OAuth2Router.AuthorizationFailureErrorCode {
+                    if let vc = navVC.visibleViewController as? PromptLoginPresenter {
+                        return vc.presentPromptLoginControllerIfNeeded()
+                    }
+                } else if let vc = navVC.visibleViewController as? ErrorAlertPresenter {
+                    return vc.presentErrorAlertController(error!)
+                }
+            }
+        }
+    }
 }

        switch OAuth2Client.sharedClient.state {
        case .Authorized:
            PacketInfoManager.sharedManager.fetchLatestPacketLog(completion: { error in
                if error == nil {
                    return
                }

                if let tabBarController = self.window?.rootViewController as? UITabBarController {
                    if let navVC = tabBarController.selectedViewController as? UINavigationController {
                        if error!.domain == OAuth2Router.APIErrorDomain && error!.code == OAuth2Router.AuthorizationFailureErrorCode {
                            if let vc = navVC.visibleViewController as? PromptLoginPresenter {
                                return vc.presentPromptLoginControllerIfNeeded()
                            }
                        } else if let vc = navVC.visibleViewController as? ErrorAlertPresenter {
                            return vc.presentErrorAlertController(error!)
                        }
                    }
                }
            })
        default:
            break

                let credential = OAuth2Credential(dictionary: dict)
                if credential.save() {
                    OAuth2Client.sharedClient.authorized(credential: credential)
                    PacketInfoManager.sharedManager.fetchLatestPacketLog(completion: { error in
                        self.handleAPIError(error)
                    })
                    return true
                }
            }
