1313use Magento \Framework \Autoload \Populator ;
1414use Magento \Framework \Config \File \ConfigFilePool ;
1515use Magento \Framework \Filesystem \DriverPool ;
16+ use Magento \Framework \HTTP \PhpEnvironment \Response ;
1617use Psr \Log \LoggerInterface ;
1718
1819/**
@@ -386,7 +387,7 @@ private function initErrorHandler()
386387 $ handler = new ErrorHandler ();
387388 set_error_handler ([$ handler , 'handler ' ]);
388389 }
389-
390+
390391 /**
391392 * Getter for error code
392393 *
@@ -428,9 +429,13 @@ public function isDeveloperMode()
428429 */
429430 protected function terminate (\Throwable $ e )
430431 {
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 ' );
432437 if ($ this ->isDeveloperMode ()) {
433- echo $ e ;
438+ $ response -> setBody ( $ e ) ;
434439 } else {
435440 $ message = "An error has happened during application run. See exception log for details. \n" ;
436441 try {
@@ -441,8 +446,9 @@ protected function terminate(\Throwable $e)
441446 } catch (\Exception $ e ) {
442447 $ message .= "Could not write error message to log. Please use developer mode to see the message. \n" ;
443448 }
444- echo $ message ;
449+ $ response -> setBody ( $ message) ;
445450 }
451+ $ response ->sendResponse ();
446452 exit (1 );
447453 }
448454 // phpcs:enable
0 commit comments