/**
  * render the HttpException in the general case
  *
  * @param HttpException $error an instance of HttpException
  * @return void
  */
 protected function defaultHttpRender(HttpException $error)
 {
     $url = $this->controller->request->here();
     $code = $error->getCode() >= 400 && $error->getCode() < 506 ? $error->getCode() : 500;
     $this->controller->response->statusCode($code);
     $this->controller->set(array('code' => $code, 'name' => h(get_class($error)), 'message' => h($error->getMessage()), 'url' => h($url), 'error' => $error, '_serialize' => array('code', 'name', 'message', 'url')));
     $template = $code >= 400 && $code < 500 ? 'error400' : 'error500';
     $this->_outputMessage($template);
 }
Example #2
-1
 public function run()
 {
     if (($exception = Yii::$app->getErrorHandler()->exception) === null) {
         // action has been invoked not from error handler, but by direct route, so we display '404 Not Found'
         $exception = new HttpException(404, Yii::t('yii', 'Page not found.'));
     }
     if ($exception instanceof HttpException) {
         $code = $exception->statusCode;
     } else {
         $code = $exception->getCode();
     }
     if ($exception instanceof Exception) {
         $name = $exception->getName();
     } else {
         $name = $this->defaultName ?: Yii::t('yii', 'Error');
     }
     if ($code) {
         $name .= " (#{$code})";
     }
     if ($exception instanceof UserException) {
         $message = $exception->getMessage();
     } else {
         $message = $this->defaultMessage ?: Yii::t('yii', 'An internal server error occurred.');
     }
     if (Yii::$app->getRequest()->getIsAjax()) {
         return "{$name}: {$message}";
     } else {
         return $this->controller->render($this->view ?: $this->id, ['name' => $name, 'message' => $message, 'exception' => $exception]);
     }
 }
Example #3
-1
 /**
  * Converts an exception into an array.
  * @param \Exception $exception the exception being converted
  * @return array the array representation of the exception.
  */
 protected function convertExceptionToArray($exception)
 {
     if (!YII_DEBUG && !$exception instanceof UserException && !$exception instanceof HttpException) {
         $exception = new HttpException(500, 'There was an error at the server.');
     }
     $array = ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
     if ($exception instanceof LBUserException) {
         $array['data'] = $exception->getErrors();
     }
     return $array;
 }