示例#1
0
 /**
  * {@inheritdoc}
  */
 public function run(Core $app, Http $answer) : Answer
 {
     # Set a default error
     $answer->setStatus(500);
     $data['error'] = $data['title'] = 'Exception';
     # Create the render and set some attributes
     $render = new Html($app->getCore() . 'views/exception.php');
     if ($app->getException() !== null) {
         # Core custom exception only
         if ($app->getException() instanceof \Core\HttpException) {
             $answer->setStatus($app->getException()->getStatus());
         }
         if (defined('insight')) {
             # Get the detailed exception
             $data['error'] = sprintf("%s\n\n#  %s(%s)\n%s", $app->getException()->getMessage(), $app->getException()->getFile(), $app->getException()->getLine(), str_replace('Stack trace:', '', $app->getException()->getTraceAsString()));
         } else {
             # Get an user acceptable error message
             $data['error'] = $app->getException()->getMessage();
         }
     }
     # Returns the answer
     return $answer->setData($render->run($app, $data));
 }