forked from activist-org/activist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request activist-org#908 from to-sta/custom_logger
custom bad request error logs setup
- Loading branch information
Showing
2 changed files
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import logging | ||
from typing import Any | ||
|
||
from rest_framework.response import Response | ||
from rest_framework.views import exception_handler | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def bad_request_logger(exception: Any, context: dict[str, Any]) -> Response | None: | ||
# Get the DRF exception handler standard error response | ||
response = exception_handler(exception, context) | ||
|
||
if response is not None: | ||
logger.warning( | ||
f"Bad request: {context['request'].path} -" | ||
f"Status Code: {response.status_code} -" | ||
f"Data: {response.data} -" | ||
) | ||
|
||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters