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

Commit 8c2ba97

Browse files
author
Mateusz Lopacinski
committed
Set fallback for Whoops < 2.1.5
1 parent 57efae3 commit 8c2ba97

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Middleware/WhoopsErrorResponseGenerator.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ public function __invoke($e, ServerRequestInterface $request, ResponseInterface
5959

6060
// Set Json content type header
6161
if ($handler instanceof JsonResponseHandler) {
62-
$response = $response->withHeader('Content-Type', $handler->contentType());
62+
$contentType = 'application/json';
63+
64+
// Whoops < 2.1.5 does not provide contentType method
65+
if (method_exists($handler, 'contentType')) {
66+
$contentType = $handler->contentType();
67+
}
68+
69+
$response = $response->withHeader('Content-Type', $contentType);
6370
}
6471
}
6572

test/Middleware/WhoopsErrorResponseGeneratorTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ public function testJsonContentTypeResponseWithJsonResponseHandler()
118118
$error = new RuntimeException();
119119

120120
$handler = $this->prophesize(JsonResponseHandler::class);
121-
$handler->contentType()->willReturn('application/json');
121+
122+
if (method_exists(JsonResponseHandler::class, 'contentType')) {
123+
$handler->contentType()->willReturn('application/json');
124+
}
122125

123126
$this->whoops->getHandlers()->willReturn([$handler->reveal()]);
124127
$this->whoops->handleException($error)->willReturn('error');

0 commit comments

Comments
 (0)