Skip to content

Commit fd8749f

Browse files
author
Oleksandr Dubovyk
committed
MC-38770: Exception during initialization is cacheable
- fixed
1 parent 2cf0433 commit fd8749f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/internal/Magento/Framework/App/Bootstrap.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ private function initErrorHandler()
386386
$handler = new ErrorHandler();
387387
set_error_handler([$handler, 'handler']);
388388
}
389-
389+
390390
/**
391391
* Getter for error code
392392
*
@@ -428,9 +428,13 @@ public function isDeveloperMode()
428428
*/
429429
protected function terminate(\Throwable $e)
430430
{
431-
431+
/** @var \Magento\Framework\HTTP\PhpEnvironment\Response $response */
432+
$response = $this->objectManager->get(\Magento\Framework\HTTP\PhpEnvironment\Response::class);
433+
$response->clearHeaders();
434+
$response->setHttpResponseCode(500);
435+
$response->setHeader('Content-Type', 'text/plain');
432436
if ($this->isDeveloperMode()) {
433-
echo $e;
437+
$response->setBody($e);
434438
} else {
435439
$message = "An error has happened during application run. See exception log for details.\n";
436440
try {
@@ -441,8 +445,9 @@ protected function terminate(\Throwable $e)
441445
} catch (\Exception $e) {
442446
$message .= "Could not write error message to log. Please use developer mode to see the message.\n";
443447
}
444-
echo $message;
448+
$response->setBody($message);
445449
}
450+
$response->sendResponse();
446451
exit(1);
447452
}
448453
// phpcs:enable

0 commit comments

Comments
 (0)