From f2014501166d3a9d65a27c4ad0f3c121e08d1e3f Mon Sep 17 00:00:00 2001 From: Nikolay Novikov Date: Tue, 19 Mar 2024 15:59:43 +0300 Subject: [PATCH] patch --- src/Providers/LaravelAtomServiceProvider.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Providers/LaravelAtomServiceProvider.php b/src/Providers/LaravelAtomServiceProvider.php index 7721ab0..85f1d39 100644 --- a/src/Providers/LaravelAtomServiceProvider.php +++ b/src/Providers/LaravelAtomServiceProvider.php @@ -110,21 +110,21 @@ private function exceptionHandler() } }); - // HttpException => verified + // HttpException [verified] $exceptionHandler->renderable(function (HttpException $e, $request) { if ($request->expectsJson() && $e->getMessage() == 'Your email address is not verified.') { return response()->json(['message' => $e->getMessage(), 'errors' => ['error' => [trans($e->getMessage())]]], $e->getStatusCode()); } }); - // TokenMismatchException + // TokenMismatchException, HttpException [token mismatch] $exceptionHandler->renderable(function (TokenMismatchException|HttpException $e, $request) { if ($request->expectsJson() && stripos($e->getMessage(), 'token mismatch') !== false) { return response()->json(['message' => $e->getMessage(), 'errors' => []], $e->getStatusCode()); } }); - // JsonEncodingException [on json columns], InvalidArgumentException [on json content-type], QueryException [etc] + // JsonEncodingException [on json columns], InvalidArgumentException [on json content-type], QueryException [invalid encoding] $exceptionHandler->renderable(function (JsonEncodingException|\InvalidArgumentException|QueryException $e, $request) { if ( $e instanceof JsonEncodingException @@ -132,7 +132,7 @@ private function exceptionHandler() || ($e instanceof QueryException && stripos($e->getMessage(), 'invalid byte sequence for encoding "UTF8"') !== false) ) { if ($request->expectsJson()) { - return response(['message' => 'Malformed UTF-8 characters, possibly incorrectly encoded.'], 400); + return response(['message' => 'Malformed UTF-8 characters, possibly incorrectly encoded.', 'errors' => []], 400); } else { return response('Malformed UTF-8 characters, possibly incorrectly encoded.', 400); } @@ -142,7 +142,9 @@ private function exceptionHandler() // MassAssignmentException $exceptionHandler->renderable(function (\Illuminate\Database\Eloquent\MassAssignmentException $e, $request) { if ($request->expectsJson()) { - return response()->json(['message' => $e->getMessage(), 'errors' => []], $e->getStatusCode()); + return response()->json(['message' => $e->getMessage(), 'errors' => []], 400); + } else { + return response($e->getMessage(), 400); } }); }