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

Commit c6db5b1

Browse files
committed
Merge branch 'hotfix/627'
Close #627 Fixes #626
2 parents 424a5bd + af84c3a commit c6db5b1

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
## 3.0.3 - TBD
5+
## 3.0.3 - 2018-07-25
66

77
### Added
88

@@ -22,7 +22,10 @@ All notable changes to this project will be documented in this file, in reverse
2222

2323
### Fixed
2424

25-
- Nothing.
25+
- [#627](https://github.com/zendframework/zend-expressive/pull/627) fixes an issue in the Whoops response generator; previously, if an error or
26+
exception occurred in an `ErrorHandler` listener or prior to handling the pipeline,
27+
Whoops would fail to intercept, resulting in an empty response with status 200. With
28+
the patch, it properly intercepts and displays the errors.
2629

2730
## 3.0.2 - 2018-04-10
2831

src/Container/WhoopsFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public function __invoke(ContainerInterface $container) : Whoops
5353
$config = $config['whoops'] ?? [];
5454

5555
$whoops = new Whoops();
56-
$whoops->writeToOutput(false);
5756
$whoops->allowQuit(false);
5857
$whoops->pushHandler($container->get('Zend\Expressive\WhoopsPageHandler'));
5958
$this->registerJsonHandler($whoops, $config);

src/Middleware/WhoopsErrorResponseGenerator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@ public function __invoke(
7979

8080
$response = $response->withStatus(Utils::getStatusCode($e, $response));
8181

82+
$sendOutputFlag = $this->whoops->writeToOutput();
83+
$this->whoops->writeToOutput(false);
8284
$response
8385
->getBody()
8486
->write($this->whoops->handleException($e));
87+
$this->whoops->writeToOutput($sendOutputFlag);
8588

8689
return $response;
8790
}

test/Middleware/WhoopsErrorResponseGeneratorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@ public function setUp()
5757
public function testWritesResultsOfWhoopsExceptionsHandlingToResponse()
5858
{
5959
$error = new RuntimeException();
60+
$sendOutputFlag = true;
6061

6162
$this->whoops->getHandlers()->willReturn([]);
6263
$this->whoops->handleException($error)->willReturn('WHOOPS');
64+
$this->whoops->writeToOutput()->willReturn($sendOutputFlag);
65+
$this->whoops->writeToOutput(false)->shouldBeCalled();
66+
$this->whoops->writeToOutput($sendOutputFlag)->shouldBeCalled();
6367

6468
// Could do more assertions here, but these will be sufficent for
6569
// ensuring that the method for injecting metadata is never called.
@@ -83,6 +87,7 @@ public function testWritesResultsOfWhoopsExceptionsHandlingToResponse()
8387
public function testAddsRequestMetadataToWhoopsPrettyPageHandler()
8488
{
8589
$error = new RuntimeException('STATUS_INTERNAL_SERVER_ERROR', StatusCode::STATUS_INTERNAL_SERVER_ERROR);
90+
$sendOutputFlag = true;
8691

8792
$handler = $this->prophesize(PrettyPageHandler::class);
8893
$handler
@@ -100,6 +105,9 @@ public function testAddsRequestMetadataToWhoopsPrettyPageHandler()
100105

101106
$this->whoops->getHandlers()->willReturn([$handler->reveal()]);
102107
$this->whoops->handleException($error)->willReturn('WHOOPS');
108+
$this->whoops->writeToOutput()->willReturn($sendOutputFlag);
109+
$this->whoops->writeToOutput(false)->shouldBeCalled();
110+
$this->whoops->writeToOutput($sendOutputFlag)->shouldBeCalled();
103111

104112
$this->request->getAttribute('originalUri', false)->willReturn('https://example.com/foo');
105113
$this->request->getAttribute('originalRequest', false)->will([$this->request, 'reveal']);
@@ -128,6 +136,7 @@ public function testAddsRequestMetadataToWhoopsPrettyPageHandler()
128136
public function testJsonContentTypeResponseWithJsonResponseHandler()
129137
{
130138
$error = new RuntimeException('STATUS_NOT_IMPLEMENTED', StatusCode::STATUS_NOT_IMPLEMENTED);
139+
$sendOutput = true;
131140

132141
$handler = $this->prophesize(JsonResponseHandler::class);
133142

@@ -137,6 +146,9 @@ public function testJsonContentTypeResponseWithJsonResponseHandler()
137146

138147
$this->whoops->getHandlers()->willReturn([$handler->reveal()]);
139148
$this->whoops->handleException($error)->willReturn('error');
149+
$this->whoops->writeToOutput()->willReturn($sendOutput);
150+
$this->whoops->writeToOutput(false)->shouldBeCalled();
151+
$this->whoops->writeToOutput($sendOutput)->shouldBeCalled();
140152

141153
$this->request->getAttribute('originalUri', false)->willReturn('https://example.com/foo');
142154
$this->request->getAttribute('originalRequest', false)->will([$this->request, 'reveal']);

0 commit comments

Comments
 (0)