Skip to content

Commit d7d2fa5

Browse files
committed
fix: expand try-catch to include kernel boot and request creation
Include all pre-output bootstrap steps in the try-catch so that kernel boot failures (e.g. misconfigured bundles) also return 503 instead of a PHP error page with HTTP 200.
1 parent 60581b2 commit d7d2fa5

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

public/index.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@
1717
if ($_ENV['APP_ENV'] === 'prod' && strlen($_ENV['APP_SECRET']) < 32) {
1818
throw new \RuntimeException('APP_SECRET must be at least 32 characters long in production.');
1919
}
20+
21+
$debug = filter_var($_ENV['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN);
22+
23+
if ($debug) {
24+
umask(0000);
25+
26+
Debug::enable();
27+
}
28+
29+
if ($trustedProxies = $_ENV['TRUSTED_PROXIES'] ?? false) {
30+
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
31+
}
32+
33+
if ($trustedHosts = $_ENV['TRUSTED_HOSTS'] ?? false) {
34+
Request::setTrustedHosts(explode(',', $trustedHosts));
35+
}
36+
37+
$kernel = new Kernel($_ENV['APP_ENV'], $debug);
38+
$request = Request::createFromGlobals();
2039
} catch (\Throwable $e) {
2140
http_response_code(503);
2241
header('Content-Type: application/json');
@@ -28,25 +47,6 @@
2847
echo json_encode($body) ?: '{"status":"DOWN"}';
2948
exit;
3049
}
31-
32-
$debug = filter_var($_ENV['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN);
33-
34-
if ($debug) {
35-
umask(0000);
36-
37-
Debug::enable();
38-
}
39-
40-
if ($trustedProxies = $_ENV['TRUSTED_PROXIES'] ?? false) {
41-
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
42-
}
43-
44-
if ($trustedHosts = $_ENV['TRUSTED_HOSTS'] ?? false) {
45-
Request::setTrustedHosts(explode(',', $trustedHosts));
46-
}
47-
48-
$kernel = new Kernel($_ENV['APP_ENV'], $debug);
49-
$request = Request::createFromGlobals();
5050
$response = $kernel->handle($request);
5151
$response->send();
5252
$kernel->terminate($request, $response);

src/OpenConext/EngineBlockBundle/EventListener/FallbackExceptionListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function onKernelException(ExceptionEvent $event)
8080
$path = $event->getRequest()->getPathInfo();
8181
if (in_array($path, ['/health', '/internal/health', '/info', '/internal/info'], true)) {
8282
$event->setResponse(new JsonResponse(
83-
['status' => 'DOWN', 'message' => $exception->getMessage()],
83+
['status' => 'DOWN'],
8484
JsonResponse::HTTP_SERVICE_UNAVAILABLE
8585
));
8686
return;

0 commit comments

Comments
 (0)