Example #1
0
 /**
  * Sets up error-handling routines.
  *
  * UserFrosting uses Slim's custom error handler to log the error trace in the PHP error log, and then generates a client-side alert (SERVER_ERROR).
  * It can also take specific actions for certain types of exceptions, such as those thrown from middleware.
  */
 public function setupErrorHandling()
 {
     /**** Error Handling Setup ****/
     // Custom error-handler: send a generic message to the client, but put the specific error info in the error log.
     // A Slim application uses its built-in error handler if its debug setting is true; otherwise, it uses the custom error handler.
     //error_log("Registering error handler");
     $this->error(function (\Exception $e) {
         if ($e instanceof AuthExpiredException) {
             $controller = new AccountController($this);
             return $this->logout(true);
         }
         if ($e instanceof AccountInvalidException) {
             $controller = new AccountController($this);
             return $this->logout(false);
         }
         if ($e instanceof AuthCompromisedException) {
             $controller = new AccountController($this);
             return $controller->pageAccountCompromised();
         }
         if ($e instanceof \PDOException) {
             // Log this error
             error_log("Error in " . $e->getFile() . " on line " . $e->getLine() . ": " . $e->getMessage());
             error_log($e->getTraceAsString());
             // In case the error is because someone is trying to reinstall with new db info while still logged in, log them out
             session_destroy();
             $controller = new AccountController($this);
             return $controller->pageDatabaseError();
         }
         if ($this->alerts && is_object($this->alerts) && $this->translator) {
             $this->alerts->addMessageTranslated("danger", "SERVER_ERROR");
         }
         error_log("Error in " . $e->getFile() . " on line " . $e->getLine() . ": " . $e->getMessage());
         error_log($e->getTraceAsString());
     });
     // Also handle fatal errors
     register_shutdown_function([$this, "fatalHandler"]);
 }
 /**
  * Sets up error-handling routines.
  *
  * UserFrosting uses Slim's custom error handler to log the error trace in the PHP error log, and then generates a client-side alert (SERVER_ERROR).
  * It can also take specific actions for certain types of exceptions, such as those thrown from middleware.
  */
 public function setupErrorHandling()
 {
     /**** Error Handling Setup ****/
     // Custom error-handler: send a generic message to the client, but put the specific error info in the error log.
     // A Slim application uses its built-in error handler if its debug setting is true; otherwise, it uses the custom error handler.
     //error_log("Registering error handler");
     $this->error(function (\Exception $e) {
         if ($e instanceof AuthExpiredException) {
             $controller = new AccountController($this);
             return $this->logout(true);
         }
         if ($e instanceof AccountDisabledException) {
             $this->logout(false);
             // Create a new session to store alerts
             $this->startSession();
             // Seems to be needed to create a new session as per http://stackoverflow.com/questions/19738422/destroying-old-session-making-new-but-php-still-refers-to-old-session
             session_regenerate_id(true);
             $this->setupServices($this->site->default_locale);
             $this->alerts->addMessageTranslated('danger', 'ACCOUNT_DISABLED');
             $this->redirect($this->urlFor('uri_home'));
         }
         if ($e instanceof AccountInvalidException) {
             $this->logout(false);
             $this->startSession();
             session_regenerate_id(true);
             $this->setupServices($this->site->default_locale);
             $this->alerts->addMessageTranslated('danger', 'ACCOUNT_INVALID');
             $this->redirect($this->urlFor('uri_home'));
         }
         if ($e instanceof AuthCompromisedException) {
             $controller = new AccountController($this);
             return $controller->pageAccountCompromised();
         }
         if ($e instanceof \PDOException) {
             // Log this error
             error_log("Error in " . $e->getFile() . " on line " . $e->getLine() . ": " . $e->getMessage());
             error_log($e->getTraceAsString());
             // In case the error is because someone is trying to reinstall with new db info while still logged in, log them out
             session_destroy();
             $controller = new AccountController($this);
             return $controller->pageDatabaseError();
         }
         if ($this->alerts && is_object($this->alerts) && $this->translator) {
             $this->alerts->addMessageTranslated("danger", "SERVER_ERROR");
         }
         error_log("Error in " . $e->getFile() . " on line " . $e->getLine() . ": " . $e->getMessage());
         error_log($e->getTraceAsString());
     });
     // Also handle fatal errors
     register_shutdown_function([$this, "fatalHandler"]);
 }