From 26cae32c0b6f18a258f8a9f1f05af68d26ffe8c7 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 19 Jan 2022 23:58:34 +0000 Subject: [PATCH] Improve exception logging --- apiserver/apiserver/api/utils.py | 7 +++++++ apiserver/apiserver/settings.py | 1 + 2 files changed, 8 insertions(+) diff --git a/apiserver/apiserver/api/utils.py b/apiserver/apiserver/api/utils.py index 5e6c2c4..39ad5c9 100644 --- a/apiserver/apiserver/api/utils.py +++ b/apiserver/apiserver/api/utils.py @@ -7,6 +7,7 @@ import requests import time from datetime import datetime, timedelta from rest_framework.exceptions import ValidationError +from rest_framework.views import exception_handler from dateutil import relativedelta from uuid import uuid4 from PIL import Image, ImageDraw, ImageFont, ImageOps @@ -417,3 +418,9 @@ def gen_member_forms(member): member.member_forms = file_name member.save() + +def custom_exception_handler(exc, context): + response = exception_handler(exc, context) + if response is not None: + logging.warning('Response: %s', json.dumps(exc.detail)) + return response diff --git a/apiserver/apiserver/settings.py b/apiserver/apiserver/settings.py index 0a6949b..167660b 100644 --- a/apiserver/apiserver/settings.py +++ b/apiserver/apiserver/settings.py @@ -209,6 +209,7 @@ REST_FRAMEWORK = { 'DEFAULT_RENDERER_CLASSES': DEFAULT_RENDERER_CLASSES, 'DEFAULT_AUTHENTICATION_CLASSES': DEFAULT_AUTHENTICATION_CLASSES, 'DEFAULT_THROTTLE_CLASSES': ['apiserver.api.throttles.LoggingThrottle'], + 'EXCEPTION_HANDLER': 'apiserver.api.utils.custom_exception_handler' } #DEFAULT_LOGGING = None