From f0c898ba209dedeb513bec31b8b6f1ec5fb04ee8 Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Fri, 2 Sep 2022 15:38:59 +0200 Subject: [PATCH] (0.6.22rc3) [halfapi] Log HTTPException with statuscode 500 as critical --- CHANGELOG.md | 1 + halfapi/__init__.py | 2 +- halfapi/halfapi.py | 9 ++++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af4d1fb..44373b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - IMPORTANT : Fix bug introduced with 0.6.20 (fix arguments handling) - Add *html* return type as default argument ret_type - Add *txt* return type +- Log HTTPException with statuscode 500 as critical ## 0.6.21 diff --git a/halfapi/__init__.py b/halfapi/__init__.py index 8c1ce75..9a102e8 100644 --- a/halfapi/__init__.py +++ b/halfapi/__init__.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -__version__ = '0.6.22-rc2' +__version__ = '0.6.22-rc3' def version(): return f'HalfAPI version:{__version__}' diff --git a/halfapi/halfapi.py b/halfapi/halfapi.py index 74c627c..7b4b76d 100644 --- a/halfapi/halfapi.py +++ b/halfapi/halfapi.py @@ -92,7 +92,7 @@ class HalfAPI(Starlette): exception_handlers={ 401: UnauthorizedResponse, 404: NotFoundResponse, - 500: InternalServerErrorResponse, + 500: HalfAPI.exception, 501: NotImplementedResponse, 503: ServiceUnavailableResponse }, @@ -148,8 +148,6 @@ class HalfAPI(Starlette): starlette_app=self) ) - - @property def version(self): return __version__ @@ -157,6 +155,11 @@ class HalfAPI(Starlette): async def version_async(self, request, *args, **kwargs): return Response(self.version) + @staticmethod + async def exception(request: Request, exc: HTTPException): + logger.critical(exc, exc_info=True) + return InternalServerErrorResponse() + @property def application(self): return self