【程序目录】优化错误获取以及返回

This commit is contained in:
吴昊天 2022-12-16 16:57:38 +08:00
parent ea91cbb123
commit 279411e94f
4 changed files with 20 additions and 56 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}