thinkphp5 Exception类重定义

重点定义本身的错误信息和错误码;php

在TP5的配置文件中有下面一段json

// 异常处理handle类 留空使用 \think\exception\Handleapp

'exception_handle'       => '',
指错误信息来自自于\think\exception\Handle的方法里;那么能够从新定义一个类,再重写这个hander方法便可;
======================================
1.定义config:
'exception_handle'       => 'app\lib\exception\ExceptionHandler',
2.在app\lib\exception\ExceptionHander.php中:
class ExceptionHandler extends Handle
{
    public function render(Exception $e)
    {
        return json('这里是自定义的错误');
        //return parent::render($e); // TODO: Change the autogenerated stub

    }
}
相关文章
相关标签/搜索