123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- declare (strict_types=1);
- namespace app\system\exception;
- use library\exceptions\AuthException;
- use library\exceptions\GeneralException;
- use think\db\exception\DbException;
- use think\exception\Handle;
- use think\Response;
- use Throwable;
- class ExecptionHandle extends Handle {
-
- public function report(Throwable $exception): void
- {
-
- parent::report($exception);
- }
-
- public function render($request, Throwable $e): Response
- {
-
- $massageData = env('app_debug', false) ? [
- 'file' => $e->getFile(),
- 'line' => $e->getLine(),
- 'trace' => $e->getTrace(),
- 'previous' => $e->getPrevious(),
- ] : [];
- if ($e instanceof DbException) {
-
- return app('json')->fail('抱歉,服务器数据异常!', ['line'=>$e->getMessage()]);
- }elseif ($e instanceof AuthException){
- return app('json')->make($e->getCode() ?: -1, $e->getMessage());
- } elseif ($e instanceof GeneralException) {
- return app('json')->make(-1, $e->getMessage());
- } else {
- return app('json')->make(-1, $e->getMessage());
- }
- }
- }
|