Skip to content

Commit

Permalink
Use repr for error logging (#1711)
Browse files Browse the repository at this point in the history
Follow-up on #1708
([comment](#1708 (comment)))

As mentioned there, there is a `__repr__` but not a `__str__`, leading
to an empty log message (for HTTPExceptions).

An example when running the dev server (previously the first line would
just be an empty line):
```
HTTPException(status_code=404, detail='Not Found')
INFO:     127.0.0.1:33538 - "GET /swaggers/ui/ HTTP/1.1" 404 Not Found
```

However, I would also be fine with just removing the logging here as
`HTTPException`s can be part of the normal flow, without indicating an
actual application error (case in point: raising a `Not Found`
exception)
  • Loading branch information
Ruwann committed Jun 13, 2023
1 parent 55f3c59 commit 59a09c7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions connexion/middleware/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import logging

from starlette.exceptions import ExceptionMiddleware as StarletteExceptionMiddleware
from starlette.exceptions import HTTPException
from starlette.middleware.exceptions import (
ExceptionMiddleware as StarletteExceptionMiddleware,
)
from starlette.requests import Request as StarletteRequest
from starlette.responses import Response
from starlette.types import ASGIApp, Receive, Scope, Send
Expand All @@ -22,7 +24,7 @@ def __init__(self, next_app: ASGIApp):

@staticmethod
def problem_handler(_request: StarletteRequest, exc: ProblemException):
logger.error(exc)
logger.error("%r", exc)

response = exc.to_problem()

Expand All @@ -35,7 +37,7 @@ def problem_handler(_request: StarletteRequest, exc: ProblemException):

@staticmethod
def http_exception(_request: StarletteRequest, exc: HTTPException) -> Response:
logger.error(exc)
logger.error("%r", exc)

headers = exc.headers

Expand All @@ -52,7 +54,7 @@ def http_exception(_request: StarletteRequest, exc: HTTPException) -> Response:

@staticmethod
def common_error_handler(_request: StarletteRequest, exc: Exception) -> Response:
logger.error(exc, exc_info=exc)
logger.error("%r", exc, exc_info=exc)

response = InternalServerError().to_problem()

Expand Down

0 comments on commit 59a09c7

Please sign in to comment.