Skip to content
Snippets Groups Projects
Commit ce9f2be9 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB
Browse files

Trying to make API exceptions nicer

parent 6c745ad4
No related branches found
No related tags found
1 merge request!8Superevents
import logging
from rest_framework.views import exception_handler
import logging
# Set up logger
logger = logging.getLogger(__name__)
def gracedb_exception_handler(exc, context):
# Call REST framework's default exception handler first,
# to get the standard error response.
response = exception_handler(exc, context)
# Combine values into one list
exc_out = [item for sublist in exc.detail.values() for item in sublist]
if hasattr(exc, 'detail') and hasattr(exc.detail, 'values'):
# Combine values into one list
exc_out = [item for sublist in exc.detail.values() for item in sublist]
# For only one exception, just print it rather than the list
if len(exc_out) == 1:
exc_out = exc_out[0]
# For only one exception, just print it rather than the list
if len(exc_out) == 1:
exc_out = exc_out[0]
# Update response data
response.data = exc_out
# Update response data
response.data = exc_out
return response
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment