Skip to content

Commit 60581b2

Browse files
committed
fix: return 503 JSON from FallbackExceptionListener for health/info routes
The fallback exception listener redirected all unhandled exceptions to the feedback page, which would return a 301 instead of an error status for the health and info endpoints. Return a JSON 503 response instead for these paths, consistent with the monitor-bundle DOWN format.
1 parent 2edfe5b commit 60581b2

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/OpenConext/EngineBlockBundle/EventListener/FallbackExceptionListener.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use EngineBlock_Exception;
2222
use OpenConext\EngineBlockBridge\ErrorReporter;
2323
use Psr\Log\LoggerInterface;
24+
use Symfony\Component\HttpFoundation\JsonResponse;
2425
use Symfony\Component\HttpFoundation\RedirectResponse;
2526
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
2627
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@@ -76,6 +77,15 @@ public function onKernelException(ExceptionEvent $event)
7677
$exception->getMessage()
7778
));
7879

80+
$path = $event->getRequest()->getPathInfo();
81+
if (in_array($path, ['/health', '/internal/health', '/info', '/internal/info'], true)) {
82+
$event->setResponse(new JsonResponse(
83+
['status' => 'DOWN', 'message' => $exception->getMessage()],
84+
JsonResponse::HTTP_SERVICE_UNAVAILABLE
85+
));
86+
return;
87+
}
88+
7989
if ($exception instanceof EngineBlock_Exception) {
8090
$this->errorReporter->reportError($exception, 'Caught Unhandled EngineBlock_Exception');
8191
} else {

0 commit comments

Comments
 (0)