magento2: 200 Response Code When Exception is Thrown During Bootstrap

Preconditions (*)

  1. Version 2.4-develop
  2. PHP 7.2

Steps to reproduce (*)

  1. Force any exception to be thrown during the bootstrapping process so that Magento\Framework\App\Bootstrap calls its terminate() function.

For example: In \Magento\Catalog\Controller\Category\View::__construct add new line: throw new \Throwable('New exception');

  1. Send GET request to http://{base_url}/catalog/category/view/id/1

Expected result (*)

  1. An error message is displayed and a non 200 response code is returned.

Actual result (*)

  1. An error message is displayed and the http response code is 200 OK.

By changing the response code to a 500 before calling exit(1), any monitoring software observing for non-200 response codes will be able to issue an alert when a bootstrap is failing.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@engcom-Charlie how is this issue fixed in 2.4-develop?

curl -IkL https://whateverdomain/category-3/category-3-1/category-3-1-1.html HTTP/2 200 server: nginx/1.14.1 date: Tue, 08 Dec 2020 16:59:04 GMT content-type: text/html; charset=UTF-8 cache-control: no-store, no-cache, must-revalidate expires: Thu, 19 Nov 1981 08:52:00 GMT pragma: no-cache set-cookie: PHPSESSID=1pucas00l87kchgbfqdeg6c4c2; expires=Tue, 08-Dec-2020 17:59:04 GMT; Max-Age=3600; path=/; domain=.gitpod.io; secure; HttpOnly vary: Accept-Encoding x-gitpod-region: production.gitpod-io.europe-west1.3 strict-transport-security: max-age=31557600

[2020-12-08 17:04:34] main.CRITICAL: ParseError: syntax error, unexpected ‘throw’ (T_THROW), expecting variable (T_VARIABLE) in /workspace/magento2gitpod/app/code/Magento/Catalog/Controller/Category/View.php:135 Stack trace: #0 /workspace/magento2gitpod/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile(‘/workspace/mage…’) #1 [internal function]: Composer\Autoload\ClassLoader->loadClass(‘Magento\Catalog…’) #2 [internal function]: spl_autoload_call(‘Magento\Catalog…’) #3 /workspace/magento2gitpod/lib/internal/Magento/Framework/App/Router/ActionList.php(127): is_subclass_of(‘Magento\Catalog…’, ‘Magento\Framewo…’) #4 /workspace/magento2gitpod/lib/internal/Magento/Framework/App/Router/Base.php(301): Magento\Framework\App\Router\ActionList->get(‘Magento_Catalog’, NULL, ‘category’, ‘view’) #5 /workspace/magento2gitpod/lib/internal/Magento/Framework/App/Router/Base.php(167): Magento\Framework\App\Router\Base->matchAction(Object(Magento\Framework\App\Request\Http), Array) #6 /workspace/magento2gitpod/lib/internal/Magento/Framework/Interception/Interceptor.php(58): Magento\Framework\App\Router\Base->match(Object(Magento\Framework\App\Request\Http)) #7 /workspace/magento2gitpod/lib/internal/Magento/Framework/Interception/Interceptor.php(138): Magento\Framework\App\Router\Base\Interceptor->___callParent(‘match’, Array) #8 /workspace/magento2gitpod/lib/internal/Magento/Framework/Interception/Interceptor.php(153): Magento\Framework\App\Router\Base\Interceptor->Magento\Framework\Interception{closure}(Object(Magento\Framework\App\Request\Http)) #9 /workspace/magento2gitpod/generated/code/Magento/Framework/App/Router/Base/Interceptor.php(23): Magento\Framework\App\Router\Base\Interceptor->___callPlugins(‘match’, Array, Array) #10 /workspace/magento2gitpod/lib/internal/Magento/Framework/App/FrontController.php(115): Magento\Framework\App\Router\Base\Interceptor->match(Object(Magento\Framework\App\Request\Http)) #11 /workspace/magento2gitpod/lib/internal/Magento/Framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http)) #12 /workspace/magento2gitpod/lib/internal/Magento/Framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent(‘dispatch’, Array) #13 /workspace/magento2gitpod/app/code/Magento/Store/App/FrontController/Plugin/RequestPreprocessor.php(99): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception{closure}(Object(Magento\Framework\App\Request\Http)) #14 /workspace/magento2gitpod/lib/internal/Magento/Framework/Interception/Interceptor.php(135): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http)) #15 /workspace/magento2gitpod/app/code/Magento/PageCache/Model/App/FrontController/BuiltinPlugin.php(75): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception{closure}(Object(Magento\Framework\App\Request\Http)) #16 /workspace/magento2gitpod/lib/internal/Magento/Framework/Interception/Interceptor.php(135): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http)) #17 /workspace/magento2gitpod/lib/internal/Magento/Framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception{closure}(Object(Magento\Framework\App\Request\Http)) #18 /workspace/magento2gitpod/generated/code/Magento/Framework/App/FrontController/Interceptor.php(23): Magento\Framework\App\FrontController\Interceptor->___callPlugins(‘dispatch’, Array, NULL) #19 /workspace/magento2gitpod/lib/internal/Magento/Framework/App/Http.php(116): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http)) #20 /workspace/magento2gitpod/generated/code/Magento/Framework/App/Http/Interceptor.php(23): Magento\Framework\App\Http->launch() #21 /workspace/magento2gitpod/lib/internal/Magento/Framework/App/Bootstrap.php(263): Magento\Framework\App\Http\Interceptor->launch() #22 /workspace/magento2gitpod/pub/index.php(29): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor)) #23 {main} [] []

Tried to replicate the same what was reported here initially by adding throw new \Throwable(‘New exception’); to the public function __construct( in View.php under Magento_Catalog Controller.

image