Skip to content

Commit

Permalink
feat: support ignore exception
Browse files Browse the repository at this point in the history
  • Loading branch information
jiannei committed Oct 18, 2023
1 parent 0a3300e commit 35d1ffe
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/Support/Traits/ExceptionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ protected function prepareJsonResponse($request, $e)
// 或者是 ajax 请求,header 中包含 X-Requested-With:XMLHttpRequest;
$exceptionConfig = Config::get('response.exception.'.get_class($e));

if (! is_null($exceptionConfig)) {
return parent::prepareJsonResponse($request, $e);
}
if ($exceptionConfig === false) return parent::prepareJsonResponse($request, $e);

/** @var \Illuminate\Foundation\Exceptions\Handler $this */
$isHttpException = $this->isHttpException($e);
Expand Down Expand Up @@ -85,7 +83,7 @@ protected function invalidJson($request, ValidationException $exception)
{
$exceptionConfig = Config::get('response.exception.'.ValidationException::class);

return ! is_null($exceptionConfig) ? Response::fail(
return $exceptionConfig !== false ? Response::fail(
$exception->validator->errors()->first(),
Arr::get($exceptionConfig, 'code', 422),
$exception->errors()
Expand All @@ -102,7 +100,7 @@ protected function unauthenticated($request, AuthenticationException $exception)
{
$exceptionConfig = Config::get('response.exception.'.AuthenticationException::class);

return $exceptionConfig && $request->expectsJson()
return $exceptionConfig !== false && $request->expectsJson()
? Response::errorUnauthorized($exceptionConfig['message'] ?? $exception->getMessage())
: parent::unauthenticated($request, $exception);
}
Expand Down

0 comments on commit 35d1ffe

Please sign in to comment.