1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace app;
- use app\model\CommonModel;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\ModelNotFoundException;
- use think\Exception;
- 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 ($e instanceof ValidateException) return json_show(CommonModel::$error_param, $e->getError());
- elseif ($e instanceof Exception) return json_show(CommonModel::$error_default, $e->getMessage());
- else return json_show(CommonModel::$error_other, $e->getMessage());
- }
- }
|