不可预知得内部异常处理

复制provider.php到模块下

<?php
use app\ExceptionHandle;
use app\Request;

// 容器Provider定义文件
return [

    'think\exception\Handle' =>'app\\demo\\exception\\Http',
];

在模块下新建exception文件夹,新建http类

<?php

namespace app\demo\exception;

use think\exception\Handle;
use think\Response;
use Throwable;

class Http extends Handle
{
protected $httpStatus = 500;

public function render($request, Throwable $e): Response
{
if( method_exists($e, "getStatusCode") ) {
$httpStatus = $e->getStatusCode();
} else {
$httpStatus = $this->httpStatus;
}
// public $httpStatus = 500;
return show(config('status.error'), $e->getMessage(), [], $httpStatus);

}

}

  

posted @ 2020-03-27 00:56  X__cicada  阅读(148)  评论(0编辑  收藏  举报