1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace app\api\library;
- use Exception;
- use think\exception\Handle;
- class ExceptionHandle extends Handle
- {
- public function render(Exception $e)
- {
-
- if (!\think\Config::get('app_debug')) {
- $statuscode = $code = 500;
- $msg = $e->getMessage();
-
- if ($e instanceof \think\exception\ValidateException) {
- $code = 0;
- $statuscode = 200;
- $msg = $e->getError();
- }
-
- if ($e instanceof \think\exception\HttpException) {
- $statuscode = $code = $e->getStatusCode();
- $msg = $e->getMessage();
- }
- return json(['code' => $code, 'msg' => $msg, 'time' => time(), 'data' => null], $statuscode);
- }
-
- return parent::render($e);
- }
- }
|