From b7b1f56d0c86ebeeb1d2b6043baf7bfc9a6a52e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Guti=C3=A9rrez?= Date: Wed, 20 Jan 2016 10:58:45 +0100 Subject: [PATCH] stream write fix --- src/Exception/OAuthServerException.php | 4 ++-- src/Middleware/AuthenticationServerMiddleware.php | 4 +++- src/Middleware/ResourceServerMiddleware.php | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Exception/OAuthServerException.php b/src/Exception/OAuthServerException.php index b0309290..c68c541d 100644 --- a/src/Exception/OAuthServerException.php +++ b/src/Exception/OAuthServerException.php @@ -243,9 +243,9 @@ class OAuthServerException extends \Exception $response = $response->withHeader($header, $content); } - $response = $response->withStatus($this->getHttpStatusCode()); $response->getBody()->write(json_encode($payload)); - return $response; + + return $response->withStatus($this->getHttpStatusCode()); } /** diff --git a/src/Middleware/AuthenticationServerMiddleware.php b/src/Middleware/AuthenticationServerMiddleware.php index a71d4218..14ac1c32 100644 --- a/src/Middleware/AuthenticationServerMiddleware.php +++ b/src/Middleware/AuthenticationServerMiddleware.php @@ -38,7 +38,9 @@ class AuthenticationServerMiddleware } catch (OAuthServerException $exception) { return $exception->generateHttpResponse($response); } catch (\Exception $exception) { - return $response->withStatus(500)->write($exception->getMessage()); + $response->getBody()->write($exception->getMessage()); + + return $response->withStatus(500); } if (in_array($response->getStatusCode(), [400, 401, 500])) { diff --git a/src/Middleware/ResourceServerMiddleware.php b/src/Middleware/ResourceServerMiddleware.php index ebcf2794..1794cdce 100644 --- a/src/Middleware/ResourceServerMiddleware.php +++ b/src/Middleware/ResourceServerMiddleware.php @@ -38,7 +38,9 @@ class ResourceServerMiddleware } catch (OAuthServerException $exception) { return $exception->generateHttpResponse($response); } catch (\Exception $exception) { - return $response->withStatus(500)->write($exception->getMessage()); + $response->getBody()->write($exception->getMessage()); + + return $response->withStatus(500); } // Pass the request and response on to the next responder in the chain