yii\web\ErrorHandler::convertExceptionToArray PHP Метод

convertExceptionToArray() защищенный Метод

Converts an exception into an array.
protected convertExceptionToArray ( Exception $exception ) : array
$exception Exception the exception being converted
Результат array the array representation of the exception.
    protected function convertExceptionToArray($exception)
    {
        if (!YII_DEBUG && !$exception instanceof UserException && !$exception instanceof HttpException) {
            $exception = new HttpException(500, Yii::t('yii', 'An internal server error occurred.'));
        }
        $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;
    }

Usage Example

Пример #1
0
 /**
  * @inheritdoc
  */
 protected function convertExceptionToArray($exception)
 {
     $array = parent::convertExceptionToArray($exception);
     if ($exception instanceof ErrorsException) {
         $array['errors'] = $exception->errors;
     }
     return $array;
 }