Skip to content

Commit

Permalink
Merge pull request #759 from fecgov/feature/689
Browse files Browse the repository at this point in the history
689 - Update output to print to sysout while refusing all errors or exceptions that are not validation related from going to the front end
  • Loading branch information
toddlees authored Mar 7, 2024
2 parents 5ac27d4 + 03eb3b4 commit 2bb13b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
1 change: 0 additions & 1 deletion django-backend/fecfiler/transactions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from fecfiler.transactions.schedule_c2.views import save_hook as schedule_c2_save_hook
from fecfiler.transactions.schedule_d.views import save_hook as schedule_d_save_hook
import structlog

logger = structlog.get_logger(__name__)


Expand Down
23 changes: 15 additions & 8 deletions django-backend/fecfiler/utils.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
from rest_framework.exceptions import ValidationError
from django.http import HttpResponseServerError
from fecfiler.authentication.views import delete_user_logged_in_cookies
from rest_framework.views import exception_handler
# from django.http import HttpResponseServerError
# from fecfiler.settings import DEBUG
import structlog

logger = structlog.get_logger(__name__)


def custom_exception_handler(exc, context):
# Call REST framework's default exception handler first,
# to get the standard error response.
response = exception_handler(exc, context)
# if response is None:
# return HttpResponseServerError()

if response is None:
return HttpResponseServerError()

# Delete user cookies on forbidden http response.
# this will ensure that when the user is redirected
# to the login page due to the 403, any cookies
# (such as indicating committee id) are removed to
# allow for a clean new login.
if response is not None and response.status_code == 403:
if response.status_code == 403:
delete_user_logged_in_cookies(response)

# Do not allow an error response body
# if getattr(response, 'data'):
# response.data = None
# Do not allow an error response body unless validation
data = getattr(response, 'data')
exception_type = type(exc)
logger.error(f"Error: {data}")
if data and exception_type is not ValidationError:
response.data = None

return response

0 comments on commit 2bb13b5

Please sign in to comment.