From 3e9ec56d1e0e83bc1bd00244f1ad9af7be3c44af Mon Sep 17 00:00:00 2001 From: Sylvain Brunato <61419125+sbrunato@users.noreply.github.com> Date: Fri, 1 Sep 2023 13:00:14 +0200 Subject: [PATCH] fix(server): handle DownloadError and RequestError in server mode (#806) --- eodag/rest/server.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/eodag/rest/server.py b/eodag/rest/server.py index 057fb8631..7364fe8ba 100755 --- a/eodag/rest/server.py +++ b/eodag/rest/server.py @@ -56,9 +56,11 @@ from eodag.utils import parse_header, update_nested_dict from eodag.utils.exceptions import ( AuthenticationError, + DownloadError, MisconfiguredError, NoMatchingProductType, NotAvailableError, + RequestError, UnsupportedProductType, UnsupportedProvider, ValidationError, @@ -249,6 +251,20 @@ async def handle_auth_error(request: Request, error): ) +@app.exception_handler(DownloadError) +@app.exception_handler(RequestError) +async def handle_server_error(request: Request, error): + """These errors should be sent as internal server error with details to the client""" + logger.error(f"{type(error).__name__}: {str(error)}") + return await default_exception_handler( + request, + HTTPException( + status_code=500, + detail=f"{type(error).__name__}: {str(error)}", + ), + ) + + @router.get("/", tags=["Capabilities"]) def catalogs_root(request: Request): """STAC catalogs root"""