From 998b363d9c7307a9bcd4437380a2047b7c7aae86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=8A=9B=E5=BC=BA?= Date: Wed, 1 Mar 2023 14:46:46 +0800 Subject: [PATCH] =?UTF-8?q?improve:=20=E4=BC=98=E5=8C=96=E4=B8=8B=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crmeb/app/api/ApiExceptionHandle.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crmeb/app/api/ApiExceptionHandle.php b/crmeb/app/api/ApiExceptionHandle.php index 15cc5d842..2326d29ac 100644 --- a/crmeb/app/api/ApiExceptionHandle.php +++ b/crmeb/app/api/ApiExceptionHandle.php @@ -14,6 +14,7 @@ namespace app\api; use crmeb\exceptions\AdminException; use crmeb\exceptions\ApiException; +use crmeb\exceptions\ApiStatusException; use crmeb\exceptions\AuthException; use think\db\exception\DbException; use think\exception\Handle; @@ -86,11 +87,13 @@ class ApiExceptionHandle extends Handle ] : []; $message = Env::get('app_debug', false) ? $e->getMessage() : '很抱歉,系统开小差了'; // 添加自定义异常处理机制 + if ($e instanceof ApiStatusException) { + return app('json')->status($e->getApiStatus(), $message, $e->getApiData()); + } if ($e instanceof AuthException || $e instanceof AdminException || $e instanceof ApiException || $e instanceof ValidateException) { return app('json')->make($e->getCode() ?: 400, $message, $massageData); - } else { - return app('json')->fail($message, $massageData); } + return app('json')->fail($message, $massageData); } }