Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
AnourValar committed Mar 19, 2024
1 parent 84b763d commit f201450
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Providers/LaravelAtomServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,29 +110,29 @@ 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
|| ($e instanceof \InvalidArgumentException && stripos($e->getMessage(), 'Malformed UTF-8 characters') !== false)
|| ($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);
}
Expand All @@ -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);
}
});
}
Expand Down

0 comments on commit f201450

Please sign in to comment.