diff --git a/php/public/index.php b/php/public/index.php index e4b7cfe4..876ce9c8 100644 --- a/php/public/index.php +++ b/php/public/index.php @@ -212,4 +212,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();