From 32c8ee7d4b45340c4781387fbaee449dff724bb1 Mon Sep 17 00:00:00 2001 From: Levi Date: Wed, 11 Mar 2026 16:45:46 +0100 Subject: [PATCH 1/2] handle laravel/passport v13 error messages --- src/Exception/ExceptionFactory.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Exception/ExceptionFactory.php b/src/Exception/ExceptionFactory.php index d78b096..fb4d8c1 100644 --- a/src/Exception/ExceptionFactory.php +++ b/src/Exception/ExceptionFactory.php @@ -30,7 +30,7 @@ public static function create(int $status, string $body = ''): ?Exception case Response::HTTP_BAD_REQUEST: $body = json_decode($body, true, 512, JSON_THROW_ON_ERROR); - return new \RuntimeException("Error: $status; Body: " . $body['message']); + return new \RuntimeException("Error: $status; Body: " . self::getErrorMessage($body)); default: if ($status < 400) { return null; @@ -39,4 +39,24 @@ public static function create(int $status, string $body = ''): ?Exception return new \RuntimeException("Error: $status; Known body: $body"); } } + + private static function getErrorMessage(mixed $body): string + { + if (isset($body['message'])) { + return $body['message']; + } + + if ($body['error']) { + return json_encode( + [ + 'error' => $body['error'], + 'error_description' => $body['error_description'], + 'hint' => $body['hint'], + ], + JSON_THROW_ON_ERROR, + ); + } + + return 'unknown error'; + } } From 9396b264a5ce269d90792a9d9a6ef2ef2c18b8f8 Mon Sep 17 00:00:00 2001 From: Levivb Date: Wed, 11 Mar 2026 15:48:10 +0000 Subject: [PATCH 2/2] Apply php-cs-fixer changes --- src/Exception/ExceptionFactory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Exception/ExceptionFactory.php b/src/Exception/ExceptionFactory.php index fb4d8c1..db4c93b 100644 --- a/src/Exception/ExceptionFactory.php +++ b/src/Exception/ExceptionFactory.php @@ -49,9 +49,9 @@ private static function getErrorMessage(mixed $body): string if ($body['error']) { return json_encode( [ - 'error' => $body['error'], + 'error' => $body['error'], 'error_description' => $body['error_description'], - 'hint' => $body['hint'], + 'hint' => $body['hint'], ], JSON_THROW_ON_ERROR, );