From 279411e94f18ba5d6968de628c76c2b638366f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=98=8A=E5=A4=A9?= <442384644@qq.com> Date: Fri, 16 Dec 2022 16:57:38 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=A8=8B=E5=BA=8F=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E3=80=91=E4=BC=98=E5=8C=96=E9=94=99=E8=AF=AF=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/adminapi/AdminApiExceptionHandle.php | 19 +++++-------------- crmeb/app/api/ApiExceptionHandle.php | 19 +++++-------------- crmeb/app/kefuapi/KefuApiExceptionHandle.php | 19 +++++-------------- crmeb/app/outapi/OutApiExceptionHandle.php | 19 +++++-------------- 4 files changed, 20 insertions(+), 56 deletions(-) diff --git a/crmeb/app/adminapi/AdminApiExceptionHandle.php b/crmeb/app/adminapi/AdminApiExceptionHandle.php index be265fe5d..1927511f7 100644 --- a/crmeb/app/adminapi/AdminApiExceptionHandle.php +++ b/crmeb/app/adminapi/AdminApiExceptionHandle.php @@ -78,27 +78,18 @@ class AdminApiExceptionHandle extends Handle public function render($request, Throwable $e): Response { $massageData = Env::get('app_debug', false) ? [ + 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'trace' => $e->getTrace(), 'previous' => $e->getPrevious(), ] : []; + $message = Env::get('app_debug', false) ? '接口报错:' . $e->getMessage() : '很抱歉,系统开小差了'; // 添加自定义异常处理机制 - if ($e instanceof DbException) { - return app('json')->fail(100102, $massageData); - } elseif ($e instanceof ValidateException) { - return app('json')->fail($e->getMessage(), $massageData); - } elseif ($e instanceof AuthException || $e instanceof AdminException || $e instanceof ApiException) { - return app('json')->make($e->getCode() ?: 400, $e->getMessage(), $massageData); + if ($e instanceof AuthException || $e instanceof AdminException || $e instanceof ApiException) { + return app('json')->make($e->getCode() ?: 400, $message, $massageData); } else { - return app('json')->fail('很抱歉!系统开小差了', Env::get('app_debug', false) ? [ - 'message' => $e->getMessage(), - 'file' => $e->getFile(), - 'code' => $e->getCode(), - 'line' => $e->getLine(), - 'trace' => $e->getTrace(), - 'previous' => $e->getPrevious(), - ] : []); + return app('json')->fail($message, $massageData); } } diff --git a/crmeb/app/api/ApiExceptionHandle.php b/crmeb/app/api/ApiExceptionHandle.php index 1a775bdbc..f4b868e87 100644 --- a/crmeb/app/api/ApiExceptionHandle.php +++ b/crmeb/app/api/ApiExceptionHandle.php @@ -78,27 +78,18 @@ class ApiExceptionHandle extends Handle public function render($request, Throwable $e): Response { $massageData = Env::get('app_debug', false) ? [ + 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'trace' => $e->getTrace(), 'previous' => $e->getPrevious(), ] : []; + $message = Env::get('app_debug', false) ? '接口报错:' . $e->getMessage() : '很抱歉,系统开小差了'; // 添加自定义异常处理机制 - if ($e instanceof DbException) { - return app('json')->fail(100102, $massageData); - } elseif ($e instanceof ValidateException) { - return app('json')->fail($e->getMessage(), $massageData); - } elseif ($e instanceof AuthException || $e instanceof AdminException || $e instanceof ApiException) { - return app('json')->make($e->getCode() ?: 400, $e->getMessage(), $massageData); + if ($e instanceof AuthException || $e instanceof AdminException || $e instanceof ApiException) { + return app('json')->make($e->getCode() ?: 400, $message, $massageData); } else { - return app('json')->fail('很抱歉!系统开小差了', Env::get('app_debug', false) ? [ - 'message' => $e->getMessage(), - 'file' => $e->getFile(), - 'code' => $e->getCode(), - 'line' => $e->getLine(), - 'trace' => $e->getTrace(), - 'previous' => $e->getPrevious(), - ] : []); + return app('json')->fail($message, $massageData); } } diff --git a/crmeb/app/kefuapi/KefuApiExceptionHandle.php b/crmeb/app/kefuapi/KefuApiExceptionHandle.php index 2b44c7bc9..047e4e4ca 100644 --- a/crmeb/app/kefuapi/KefuApiExceptionHandle.php +++ b/crmeb/app/kefuapi/KefuApiExceptionHandle.php @@ -78,27 +78,18 @@ class KefuApiExceptionHandle extends Handle public function render($request, Throwable $e): Response { $massageData = Env::get('app_debug', false) ? [ + 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'trace' => $e->getTrace(), 'previous' => $e->getPrevious(), ] : []; + $message = Env::get('app_debug', false) ? '接口报错:' . $e->getMessage() : '很抱歉,系统开小差了'; // 添加自定义异常处理机制 - if ($e instanceof DbException) { - return app('json')->fail(100102, $massageData); - } elseif ($e instanceof ValidateException) { - return app('json')->fail($e->getMessage(), $massageData); - } elseif ($e instanceof AuthException || $e instanceof AdminException || $e instanceof ApiException) { - return app('json')->make($e->getCode() ?: 400, $e->getMessage(), $massageData); + if ($e instanceof AuthException || $e instanceof AdminException || $e instanceof ApiException) { + return app('json')->make($e->getCode() ?: 400, $message, $massageData); } else { - return app('json')->fail('很抱歉!系统开小差了', Env::get('app_debug', false) ? [ - 'message' => $e->getMessage(), - 'file' => $e->getFile(), - 'code' => $e->getCode(), - 'line' => $e->getLine(), - 'trace' => $e->getTrace(), - 'previous' => $e->getPrevious(), - ] : []); + return app('json')->fail($message, $massageData); } } } diff --git a/crmeb/app/outapi/OutApiExceptionHandle.php b/crmeb/app/outapi/OutApiExceptionHandle.php index 848c2b524..934247623 100644 --- a/crmeb/app/outapi/OutApiExceptionHandle.php +++ b/crmeb/app/outapi/OutApiExceptionHandle.php @@ -78,27 +78,18 @@ class OutApiExceptionHandle extends Handle public function render($request, Throwable $e): Response { $massageData = Env::get('app_debug', false) ? [ + 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'trace' => $e->getTrace(), 'previous' => $e->getPrevious(), ] : []; + $message = Env::get('app_debug', false) ? '接口报错:' . $e->getMessage() : '很抱歉,系统开小差了'; // 添加自定义异常处理机制 - if ($e instanceof DbException) { - return app('json')->fail(100102, $massageData); - } elseif ($e instanceof ValidateException) { - return app('json')->fail($e->getMessage(), $massageData); - } elseif ($e instanceof AuthException || $e instanceof AdminException || $e instanceof ApiException) { - return app('json')->make($e->getCode() ?: 400, $e->getMessage(), $massageData); + if ($e instanceof AuthException || $e instanceof AdminException || $e instanceof ApiException) { + return app('json')->make($e->getCode() ?: 400, $message, $massageData); } else { - return app('json')->fail('很抱歉!系统开小差了', Env::get('app_debug', false) ? [ - 'message' => $e->getMessage(), - 'file' => $e->getFile(), - 'code' => $e->getCode(), - 'line' => $e->getLine(), - 'trace' => $e->getTrace(), - 'previous' => $e->getPrevious(), - ] : []); + return app('json')->fail($message, $massageData); } }