Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit b3eb7d0

Browse files
committed
Add response status code for the Whoops error handler
fixes #475
1 parent cb9b006 commit b3eb7d0

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Middleware/WhoopsErrorResponseGenerator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Whoops\Handler\PrettyPageHandler;
1515
use Whoops\Run;
1616
use Whoops\RunInterface;
17+
use Zend\Stratigility\Utils;
1718

1819
class WhoopsErrorResponseGenerator
1920
{
@@ -70,6 +71,8 @@ public function __invoke($e, ServerRequestInterface $request, ResponseInterface
7071
}
7172
}
7273

74+
$response = $response->withStatus(Utils::getStatusCode($e, $response));
75+
7376
$response
7477
->getBody()
7578
->write($this->whoops->handleException($e));

test/Middleware/WhoopsErrorResponseGeneratorTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace ZendTest\Expressive\Middleware;
99

10+
use Fig\Http\Message\StatusCodeInterface as StatusCode;
1011
use PHPUnit\Framework\TestCase;
1112
use Prophecy\Prophecy\ObjectProphecy;
1213
use Psr\Http\Message\ResponseInterface;
@@ -58,7 +59,9 @@ public function testWritesResultsOfWhoopsExceptionsHandlingToResponse()
5859
$this->request->getAttribute('originalUri', false)->shouldNotBeCalled();
5960
$this->request->getAttribute('originalRequest', false)->shouldNotBeCalled();
6061

62+
$this->response->withStatus(StatusCode::STATUS_INTERNAL_SERVER_ERROR)->will([$this->response, 'reveal']);
6163
$this->response->getBody()->will([$this->stream, 'reveal']);
64+
$this->response->getStatusCode()->willReturn(StatusCode::STATUS_INTERNAL_SERVER_ERROR);
6265

6366
$this->stream->write('WHOOPS')->shouldBeCalled();
6467

@@ -101,6 +104,8 @@ public function testAddsRequestMetadataToWhoopsPrettyPageHandler()
101104
$this->request->getQueryParams()->willReturn([]);
102105
$this->request->getParsedBody()->willReturn([]);
103106

107+
$this->response->withStatus(StatusCode::STATUS_INTERNAL_SERVER_ERROR)->will([$this->response, 'reveal']);
108+
$this->response->getStatusCode()->willReturn(StatusCode::STATUS_INTERNAL_SERVER_ERROR);
104109
$this->response->getBody()->will([$this->stream, 'reveal']);
105110

106111
$this->stream->write('WHOOPS')->shouldBeCalled();
@@ -137,6 +142,8 @@ public function testJsonContentTypeResponseWithJsonResponseHandler()
137142
$this->request->getParsedBody()->willReturn([]);
138143

139144
$this->response->withHeader('Content-Type', 'application/json')->will([$this->response, 'reveal']);
145+
$this->response->withStatus(StatusCode::STATUS_INTERNAL_SERVER_ERROR)->will([$this->response, 'reveal']);
146+
$this->response->getStatusCode()->willReturn(StatusCode::STATUS_INTERNAL_SERVER_ERROR);
140147
$this->response->getBody()->will([$this->stream, 'reveal']);
141148

142149
$this->stream->write('error')->shouldBeCalled();

0 commit comments

Comments
 (0)