mirror of
https://github.com/nextcloud/all-in-one.git
synced 2026-05-21 02:40:09 +00:00
aio-interface: add custom error handler for 405 errors (#8058)
This commit is contained in:
@@ -245,6 +245,7 @@ $app->get('/', function (\Psr\Http\Message\RequestInterface $request, Response $
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Default error handler
|
||||||
$errorMiddleware = $app->addErrorMiddleware(false, true, true);
|
$errorMiddleware = $app->addErrorMiddleware(false, true, true);
|
||||||
|
|
||||||
// Set a custom Not Found handler, which doesn't pollute the app output with 404 errors.
|
// Set a custom Not Found handler, which doesn't pollute the app output with 404 errors.
|
||||||
@@ -254,6 +255,17 @@ $errorMiddleware->setErrorHandler(
|
|||||||
$response = $app->getResponseFactory()->createResponse();
|
$response = $app->getResponseFactory()->createResponse();
|
||||||
$response->getBody()->write('Not Found');
|
$response->getBody()->write('Not Found');
|
||||||
return $response->withStatus(404);
|
return $response->withStatus(404);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set another custom error handler, which doesn't pollute the app output with 405 errors.
|
||||||
|
$errorMiddleware->setErrorHandler(
|
||||||
|
\Slim\Exception\HttpMethodNotAllowedException::class,
|
||||||
|
function (Request $request, Throwable $exception, bool $displayErrorDetails) use ($app) {
|
||||||
|
$response = $app->getResponseFactory()->createResponse();
|
||||||
|
$response->getBody()->write('Method not allowed');
|
||||||
|
return $response->withStatus(405);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
$app->run();
|
$app->run();
|
||||||
|
|||||||
Reference in New Issue
Block a user