12345678910111213141516171819202122232425262728293031323334353637 |
- <?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 = 'An error occurred';
-
- if ($e instanceof \think\exception\ValidateException) {
- $code = 0;
- $statuscode = 200;
- $msg = $e->getError();
- }
-
- if ($e instanceof \think\exception\HttpException) {
- $statuscode = $code = $e->getStatusCode();
- }
- return json(['code' => $code, 'msg' => $msg, 'time' => time(), 'data' => null], $statuscode);
- }
-
- return parent::render($e);
- }
- }
|