123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace app;
-
- use think\db\exception\DataNotFoundException;
- use think\db\exception\ModelNotFoundException;
- use think\exception\Handle;
- use think\exception\HttpException;
- use think\exception\HttpResponseException;
- use think\exception\ValidateException;
- use think\Response;
- use Throwable;
-
-
- class ExceptionHandle extends Handle
- {
-
-
- protected $ignoreReport = [
- HttpException::class,
- HttpResponseException::class,
- ModelNotFoundException::class,
- DataNotFoundException::class,
- ValidateException::class,
- ];
-
-
-
- public function report(Throwable $exception): void
- {
-
- parent::report($exception);
- }
-
-
-
- public function render($request, Throwable $e): Response
- {
- if (env('APP_DEBUG',true) == false) {
-
- if ($e instanceof ValidateException) {
- $data = array('code'=>0, 'show'=> 1, 'msg'=>'参数验证错误', 'data'=>[]);
- return json($data, 200);
- }
-
-
- if ($e instanceof HttpException) {
- $data = array('code'=>0, 'show'=> 1, 'msg'=>'请求异常', 'data'=>[]);
- return json($data, 200);
- }
-
-
-
-
- }
-
-
- return parent::render($request, $e);
-
- }
- }
|