@@ 32-72 (lines=41) @@ | ||
29 | * |
|
30 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
|
31 | */ |
|
32 | class WhoopsThrowableJsonHandler extends BaseThrowableHandler |
|
33 | { |
|
34 | /** |
|
35 | * @inheritdoc |
|
36 | * |
|
37 | * @SuppressWarnings(PHPMD.ElseExpression) |
|
38 | */ |
|
39 | public function createResponse(Throwable $throwable, ContainerInterface $container): ThrowableResponseInterface |
|
40 | { |
|
41 | $message = '{"error":{"message":"Internal Server Error."}}'; |
|
42 | ||
43 | $this->logException($throwable, $container, $message); |
|
44 | ||
45 | list($isDebug) = $this->getSettings($container); |
|
46 | ||
47 | if ($isDebug === true) { |
|
48 | $run = new Run(); |
|
49 | ||
50 | // If these two options are not used it would work fine with PHP Unit and XDebug, |
|
51 | // however it produces output to console under PhpDbg. So we need a couple of |
|
52 | // tweaks to make it work predictably in both environments. |
|
53 | // |
|
54 | // this one forbids Whoops spilling output to console |
|
55 | $run->writeToOutput(false); |
|
56 | // by default after sending error to output Whoops stops execution |
|
57 | // as we want just generated output `string` we instruct not to halt |
|
58 | $run->allowQuit(false); |
|
59 | ||
60 | $handler = new JsonResponseHandler(); |
|
61 | $handler->setException($throwable); |
|
62 | $run->appendHandler($handler); |
|
63 | ||
64 | $message = $run->handleException($throwable); |
|
65 | } |
|
66 | ||
67 | $status = $throwable->getCode() > 0 ? $throwable->getCode() : static::DEFAULT_HTTP_ERROR_CODE; |
|
68 | $response = $this->createThrowableJsonResponse($throwable, $message, $status); |
|
69 | ||
70 | return $response; |
|
71 | } |
|
72 | } |
|
73 |
@@ 32-72 (lines=41) @@ | ||
29 | * |
|
30 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
|
31 | */ |
|
32 | class WhoopsThrowableTextHandler extends BaseThrowableHandler |
|
33 | { |
|
34 | /** |
|
35 | * @inheritdoc |
|
36 | * |
|
37 | * @SuppressWarnings(PHPMD.ElseExpression) |
|
38 | */ |
|
39 | public function createResponse(Throwable $throwable, ContainerInterface $container): ThrowableResponseInterface |
|
40 | { |
|
41 | $message = 'Internal Server Error'; |
|
42 | ||
43 | $this->logException($throwable, $container, $message); |
|
44 | ||
45 | list($isDebug) = $this->getSettings($container); |
|
46 | ||
47 | if ($isDebug === true) { |
|
48 | $run = new Run(); |
|
49 | ||
50 | // If these two options are not used it would work fine with PHP Unit and XDebug, |
|
51 | // however it produces output to console under PhpDbg. So we need a couple of |
|
52 | // tweaks to make it work predictably in both environments. |
|
53 | // |
|
54 | // this one forbids Whoops spilling output to console |
|
55 | $run->writeToOutput(false); |
|
56 | // by default after sending error to output Whoops stops execution |
|
57 | // as we want just generated output `string` we instruct not to halt |
|
58 | $run->allowQuit(false); |
|
59 | ||
60 | $handler = new PlainTextHandler(); |
|
61 | $handler->setException($throwable); |
|
62 | $run->appendHandler($handler); |
|
63 | ||
64 | $message = $run->handleException($throwable); |
|
65 | } |
|
66 | ||
67 | $status = $throwable->getCode() > 0 ? $throwable->getCode() : static::DEFAULT_HTTP_ERROR_CODE; |
|
68 | $response = $this->createThrowableTextResponse($throwable, $message, $status); |
|
69 | ||
70 | return $response; |
|
71 | } |
|
72 | } |
|
73 |