Skip to content

Commit

Permalink
ENGCOM-4696: fatalErrorHandler returns 500 only on fatal errors #22200
Browse files Browse the repository at this point in the history
  • Loading branch information
sidolov authored Apr 18, 2019
2 parents 46880df + 0c954cd commit 21e2680
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pub/health_check.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
* See COPYING.txt for license details.
*/

/**
* phpcs:disable PSR1.Files.SideEffects
* phpcs:disable Squiz.Functions.GlobalFunction
*/
use Magento\Framework\Config\ConfigOptionsListConstants;

// phpcs:ignore Magento2.Functions.DiscouragedFunction
register_shutdown_function("fatalErrorHandler");

try {
// phpcs:ignore Magento2.Security.IncludeFile
require __DIR__ . '/../app/bootstrap.php';
/** @var \Magento\Framework\App\ObjectManagerFactory $objectManagerFactory */
$objectManagerFactory = \Magento\Framework\App\Bootstrap::createObjectManagerFactory(BP, []);
Expand All @@ -20,6 +26,7 @@
$logger = $objectManager->get(\Psr\Log\LoggerInterface::class);
} catch (\Exception $e) {
http_response_code(500);
// phpcs:ignore Magento2.Security.LanguageConstruct
exit(1);
}

Expand All @@ -35,6 +42,7 @@
} catch (\Exception $e) {
http_response_code(500);
$logger->error("MySQL connection failed: " . $e->getMessage());
// phpcs:ignore Magento2.Security.LanguageConstruct
exit(1);
}
}
Expand All @@ -47,6 +55,7 @@
!isset($cacheConfig[ConfigOptionsListConstants::CONFIG_PATH_BACKEND_OPTIONS])) {
http_response_code(500);
$logger->error("Cache configuration is invalid");
// phpcs:ignore Magento2.Security.LanguageConstruct
exit(1);
}
$cacheBackendClass = $cacheConfig[ConfigOptionsListConstants::CONFIG_PATH_BACKEND];
Expand All @@ -57,6 +66,7 @@
} catch (\Exception $e) {
http_response_code(500);
$logger->error("Cache storage is not accessible");
// phpcs:ignore Magento2.Security.LanguageConstruct
exit(1);
}
}
Expand All @@ -70,7 +80,7 @@
function fatalErrorHandler()
{
$error = error_get_last();
if ($error !== null) {
if ($error !== null && $error['type'] === E_ERROR) {
http_response_code(500);
}
}

0 comments on commit 21e2680

Please sign in to comment.