码迷,mamicode.com
首页 > 其他好文 > 详细

tp6自定义异常

时间:2019-12-20 20:56:32      阅读:494      评论:0      收藏:0      [点我收藏+]

标签:status   ret   mes   function   ble   ESS   this   handle   pac   

使用app目录下的provider.php

<?php

use app\ExceptionHandle;

return [
    ‘think\exception\Handle‘ => ‘\\app\\demo\\exception\\Http‘,
];

  

应用目录下新建exception 新建 HttpException.php

<?php

namespace app\demo\exception;

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

class Http extends Handle
{
public $httpCode = 500;

public function render($request, Throwable $e): Response

{

if (method_exists($e,"getStatusCode")){
$httpCode = $e->getStatusCode();
}else{
$httpCode = $this->httpCode;
}
return show(config(‘code.error‘), $e->getMessage(),[],$httpCode);

}
}

 

tp6自定义异常

标签:status   ret   mes   function   ble   ESS   this   handle   pac   

原文地址:https://www.cnblogs.com/aln0825/p/12074631.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!