Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions kirovy/exception_handler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from rest_framework.views import exception_handler

from kirovy import logging
from kirovy.exceptions.view_exceptions import KirovyAPIException
from kirovy.objects import ui_objects
from kirovy.response import KirovyResponse

_LOGGER = logging.get_logger("api_exceptions")


def kirovy_exception_handler(exception: Exception, context) -> KirovyResponse[ui_objects.ErrorResponseData] | None:
"""Exception handler to deal with our custom exception types.
Expand All @@ -23,6 +26,7 @@ def kirovy_exception_handler(exception: Exception, context) -> KirovyResponse[ui
Otherwise, it calls the base DRF exception handler :func:`rest_framework.views.exception_handler`.
"""
if isinstance(exception, KirovyAPIException):
_LOGGER.exception(str(exception.detail), context=context, e=exception)
return KirovyResponse(exception.as_error_response_data(), status=exception.status_code)

return exception_handler(exception, context)
5 changes: 3 additions & 2 deletions kirovy/settings/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@
"class": "logging.StreamHandler",
},
},
"root": {
# No name will capture all logs
"": {
"handlers": ["console"],
"level": "INFO",
"level": get_env_var("DJANGO_LOG_LEVEL", "INFO"),
},
}