12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace app\api;
- use think\db\exception\DbException;
- use think\exception\Handle;
- use think\Response;
- use Throwable;
- class ApiExceptionHandle extends Handle
- {
-
- public function report(Throwable $exception): void
- {
-
- parent::report($exception);
- }
-
- public function render($request, Throwable $e): Response
- {
-
- if ($e instanceof DbException) {
- return app('json')->fail('数据获取失败',[
- 'file' => $e->getFile(),
- 'message' => $e->getMessage(),
- 'line' => $e->getLine(),
- 'trace' => $e->getTrace(),
- ]);
- }else{
- return app('json')->fail('系统出现异常',[
- 'message' => $e->getMessage(),
- 'file' => $e->getFile(),
- 'code' => $e->getCode(),
- 'line' => $e->getLine(),
- 'trace' => $e->getTrace(),
- 'previous' => $e->getPrevious(),
- ]);
- }
- }
- }
|