From 22d0da73acdbd44ae1cdd094e8e56025830d42d7 Mon Sep 17 00:00:00 2001 From: Pablo Zmdl Date: Thu, 5 Feb 2026 12:35:14 +0100 Subject: [PATCH] 404 error handler for less app output pollution Signed-off-by: Pablo Zmdl --- php/public/index.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/php/public/index.php b/php/public/index.php index 1ec42949..c4b41417 100644 --- a/php/public/index.php +++ b/php/public/index.php @@ -197,4 +197,13 @@ $app->get('/', function (\Psr\Http\Message\RequestInterface $request, Response $ $errorMiddleware = $app->addErrorMiddleware(false, true, true); +// Set a custom Not Found handler, which doesn't pollute the app output with 404 errors. +$errorMiddleware->setErrorHandler( + \Slim\Exception\HttpNotFoundException::class, + function (Request $request, Throwable $exception, bool $displayErrorDetails) use ($app) { + $response = $app->getResponseFactory()->createResponse(); + $response->getBody()->write('Not Found'); + return $response->withStatus(404); + }); + $app->run();