getName() public method

public getName ( ) : string
return string the user-friendly name of this exception
示例#1
39
 /**
  * Redefine error message for own styling
  *
  * @return string
  */
 public function actionError()
 {
     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 = Yii::t('yii', 'Error');
     }
     if ($code) {
         $name .= " (#{$code})";
     }
     if ($exception instanceof UserException) {
         $message = $exception->getMessage();
     } else {
         $message = Yii::t('yii', 'An internal server error occurred');
     }
     if (Yii::$app->getRequest()->getIsAjax()) {
         return "{$name}: {$message}";
     } else {
         $this->layout = 'main';
         return $this->render('error', ['code' => $code, 'name' => $name, 'message' => $message, 'exception' => $exception]);
     }
 }
示例#2
0
 /**
  * Runs the action
  *
  * @return string result content
  */
 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.');
     }
     $originalStatus = $exception->statusCode;
     $exception->statusCode = 200;
     $result = ['success' => false, 'originalStatus' => $originalStatus, 'name' => $name, 'message' => $message, 'exception' => $exception];
     //do not reverse
     if (Yii::$app->getRequest()->getIsAjax() || Yii::$app->getRequest()->getMethod() !== 'GET') {
         return Json::encode($result);
     } else {
         return $this->controller->render($this->view ?: $this->id, ['error' => $result]);
     }
 }
示例#3
0
 public function actionError()
 {
     if (($exception = Yii::$app->getErrorHandler()->exception) === null) {
         $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->render('error', ['name' => $name, 'message' => $message, 'exception' => $exception]);
     }
 }
 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 {
         if ($code === 403) {
             return Yii::$app->response->redirect('admin/login');
         }
         return $this->controller->render($this->view ?: $this->id, ['name' => $name, 'message' => $message, 'exception' => $exception]);
     }
 }
 public function actionError()
 {
     \Yii::$app->response->format = Response::FORMAT_JSON;
     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;
         Yii::$app->response->statusCode = $code;
     } else {
         $code = $exception->getCode();
         Yii::$app->response->statusCode = 500;
     }
     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 = Yii::t('yii', 'An internal server error occurred.');
     }
     return ['error' => $name, 'message' => $message];
 }
示例#6
0
 /**
  * Runs the action
  *
  * @return string result content
  */
 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 ?: HLib::t('messages', 'An error occurred during the process');
     }
     if (Yii::$app->getRequest()->getIsAjax()) {
         // Requête AJAX : on renvoie juste de quoi identifier l'erreur
         return "{$name}: {$message}";
     }
     // Le modèle de page utilisé dépend du code de l'erreur. Par défaut, c'est 'error.php'
     switch ($code) {
         case '404':
             $this->view = 'error404';
             break;
         default:
             break;
     }
     return $this->controller->render($this->view ?: $this->id, compact('name', 'message', 'exception'));
 }
示例#7
0
 /**
  * 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 = ['name' => $exception instanceof Exception || $exception instanceof ErrorException ? $exception->getName() : 'Exception', 'message' => $exception->getMessage(), 'code' => $exception->getCode()];
     if ($exception instanceof HttpException) {
         $array['status'] = $exception->statusCode;
     }
     if (YII_DEBUG) {
         $array['type'] = get_class($exception);
         if (!$exception instanceof UserException) {
             $array['file'] = $exception->getFile();
             $array['line'] = $exception->getLine();
             $array['stack-trace'] = explode("\n", $exception->getTraceAsString());
             if ($exception instanceof \yii\db\Exception) {
                 $array['error-info'] = $exception->errorInfo;
             }
         }
     }
     if (($prev = $exception->getPrevious()) !== null) {
         $array['previous'] = $this->convertExceptionToArray($prev);
     }
     return $array;
 }
示例#8
-1
 /**
  * Runs the action
  *
  * @return string result content
  */
 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.');
     }
     return "{$name}: {$message}";
 }