404 error handler for less app output pollution

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>
This commit is contained in:
Pablo Zmdl 2026-02-05 12:35:14 +01:00
parent fbffdeed9f
commit 769d5e9344

View file

@ -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();