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 e9108e3660
commit 22d0da73ac

View File

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