Ensure tokens are found in the database using the expected logic

This commit is contained in:
DaneEveritt 2022-05-22 16:05:58 -04:00
parent e9c633fd03
commit f7fc67344e
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 39 additions and 25 deletions

View file

@ -47,6 +47,18 @@ class Handler extends ExceptionHandler
ValidationException::class,
];
/**
* Maps exceptions to a specific response code. This handles special exception
* types that don't have a defined response code.
*
* @var array<string, int>
*/
protected static array $exceptionResponseCodes = [
AuthenticationException::class => 401,
AuthorizationException::class => 403,
ValidationException::class => 422,
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
@ -187,12 +199,14 @@ class Handler extends ExceptionHandler
*/
public static function convertToArray(Throwable $exception, array $override = []): array
{
$match = self::$exceptionResponseCodes[get_class($exception)] ?? null;
$error = [
'code' => class_basename($exception),
'status' => method_exists($exception, 'getStatusCode')
? strval($exception->getStatusCode())
: ($exception instanceof ValidationException ? '422' : '500'),
'detail' => $exception instanceof HttpExceptionInterface
: strval($match ?? '500'),
'detail' => $exception instanceof HttpExceptionInterface || !is_null($match)
? $exception->getMessage()
: 'An unexpected error was encountered while processing this request, please try again.',
];