magento2: 200 Response Code When Exception is Thrown During Bootstrap
Preconditions (*)
- Version 2.4-develop
- PHP 7.2
Steps to reproduce (*)
- 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');
- Send GET request to http://{base_url}/catalog/category/view/id/1
Expected result (*)
- An error message is displayed and a non 200 response code is returned.
Actual result (*)
- 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
- Fix - #22196 - 200 Response Code When Exception is Thrown During Bootstrap — committed to abbasalis/magento2 by deleted user 5 years ago
- Fix for https://github.com/magento/magento2/issues/22196 — committed to abbasalis/magento2 by deleted user 5 years ago
- Fix for https://github.com/magento/magento2/issues/22196 — committed to engcom-Charlie/magento2 by deleted user 4 years ago
- #22196 — committed to engcom-Charlie/magento2 by deleted user 4 years ago
@engcom-Charlie how is this issue fixed in 2.4-develop?
[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.