'errorHandler' => [
'errorAction' => 'site/error',
'class' => 'common\library\Exception' //此处新增
],
<?php
namespace common\library;
use yii\web\ErrorHandler;
/**
* 自定义异常
*/
class Exception extends ErrorHandler
{
/**
* 重写渲染异常页面方法
* @param type $exception
*/
public function renderException($exception) {
$data = [
'code' => 500,
'msg' => $exception->getMessage(),
'data' => [
'file' => $exception->getFile(),
'line' => $exception->getLine()
]
];
echo json_encode($data);
die;
}
}