13
13
use Magento \Framework \Autoload \Populator ;
14
14
use Magento \Framework \Config \File \ConfigFilePool ;
15
15
use Magento \Framework \Filesystem \DriverPool ;
16
+ use Magento \Framework \HTTP \PhpEnvironment \Response ;
16
17
use Psr \Log \LoggerInterface ;
17
18
18
19
/**
@@ -386,7 +387,7 @@ private function initErrorHandler()
386
387
$ handler = new ErrorHandler ();
387
388
set_error_handler ([$ handler , 'handler ' ]);
388
389
}
389
-
390
+
390
391
/**
391
392
* Getter for error code
392
393
*
@@ -428,9 +429,13 @@ public function isDeveloperMode()
428
429
*/
429
430
protected function terminate (\Throwable $ e )
430
431
{
431
-
432
+ /** @var Response $response */
433
+ $ response = $ this ->objectManager ->get (Response::class);
434
+ $ response ->clearHeaders ();
435
+ $ response ->setHttpResponseCode (500 );
436
+ $ response ->setHeader ('Content-Type ' , 'text/plain ' );
432
437
if ($ this ->isDeveloperMode ()) {
433
- echo $ e ;
438
+ $ response -> setBody ( $ e ) ;
434
439
} else {
435
440
$ message = "An error has happened during application run. See exception log for details. \n" ;
436
441
try {
@@ -441,8 +446,9 @@ protected function terminate(\Throwable $e)
441
446
} catch (\Exception $ e ) {
442
447
$ message .= "Could not write error message to log. Please use developer mode to see the message. \n" ;
443
448
}
444
- echo $ message ;
449
+ $ response -> setBody ( $ message) ;
445
450
}
451
+ $ response ->sendResponse ();
446
452
exit (1 );
447
453
}
448
454
// phpcs:enable
0 commit comments