Skip to content

Commit

Permalink
Log handled errors to warning. Closes #1925.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Fechner committed May 14, 2024
1 parent fcfe151 commit 9a10f29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion connexion/middleware/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ def add_exception_handler(
@staticmethod
def problem_handler(_request: ConnexionRequest, exc: ProblemException):
"""Default handler for Connexion ProblemExceptions"""
logger.error("%r", exc)

if 400 <= exc.status <= 499:
logger.warning("%r", exc)
else:
logger.error("%r", exc)

return exc.to_problem()

@staticmethod
Expand All @@ -81,6 +86,12 @@ def http_exception(
_request: StarletteRequest, exc: HTTPException, **kwargs
) -> StarletteResponse:
"""Default handler for Starlette HTTPException"""

if 400 <= exc.status_code <= 499:
logger.warning("%r", exc)
else:
logger.error("%r", exc)

logger.error("%r", exc)
return problem(
title=http_facts.HTTP_STATUS_CODES.get(exc.status_code),
Expand Down
4 changes: 2 additions & 2 deletions connexion/validators/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _validate(self, body: t.Any) -> t.Optional[dict]:
return self._validator.validate(body)
except ValidationError as exception:
error_path_msg = format_error_with_path(exception=exception)
logger.error(
logger.info(
f"Validation error: {exception.message}{error_path_msg}",
extra={"validator": "body"},
)
Expand Down Expand Up @@ -129,7 +129,7 @@ def _validate(self, body: dict):
self.validator.validate(body)
except ValidationError as exception:
error_path_msg = format_error_with_path(exception=exception)
logger.error(
logger.info(
f"Validation error: {exception.message}{error_path_msg}",
extra={"validator": "body"},
)
Expand Down

0 comments on commit 9a10f29

Please sign in to comment.