1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace app;
- use app\index\exception\ApiException;
- 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 ($e instanceof ApiException) {
- $code = $e->getCode();
- $message = $e->getMessage();
- } else {
-
- $code = $e->getCode();
- if (!$code || $code < 0) $code = config('status.err_token')[0];
- $message = $e->getMessage();
- if (!$message) $message=config('status.unknow_error')[1];
- }
- return show($code, $message);
-
-
- }
- }
|