diff --git a/src/Middleware/AuthorizationServerMiddleware.php b/src/Middleware/AuthorizationServerMiddleware.php index d33cbd31..6c2d08b2 100644 --- a/src/Middleware/AuthorizationServerMiddleware.php +++ b/src/Middleware/AuthorizationServerMiddleware.php @@ -46,9 +46,8 @@ class AuthorizationServerMiddleware return $exception->generateHttpResponse($response); // @codeCoverageIgnoreStart } catch (\Exception $exception) { - $response->getBody()->write($exception->getMessage()); - - return $response->withStatus(500); + return (new OAuthServerException($exception->getMessage(), 0, 'unknown_error', 500)) + ->generateHttpResponse($response); // @codeCoverageIgnoreEnd } diff --git a/src/Middleware/ResourceServerMiddleware.php b/src/Middleware/ResourceServerMiddleware.php index 6d67cb68..9e235c35 100644 --- a/src/Middleware/ResourceServerMiddleware.php +++ b/src/Middleware/ResourceServerMiddleware.php @@ -46,9 +46,8 @@ class ResourceServerMiddleware return $exception->generateHttpResponse($response); // @codeCoverageIgnoreStart } catch (\Exception $exception) { - $response->getBody()->write($exception->getMessage()); - - return $response->withStatus(500); + return (new OAuthServerException($exception->getMessage(), 0, 'unknown_error', 500)) + ->generateHttpResponse($response); // @codeCoverageIgnoreEnd }