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

Trying to make API exceptions look nicer

parent 18213f71
No related branches found
No related tags found
No related merge requests found
...@@ -337,6 +337,8 @@ REST_FRAMEWORK = { ...@@ -337,6 +337,8 @@ REST_FRAMEWORK = {
'events.api.backends.LigoAuthentication', 'events.api.backends.LigoAuthentication',
), ),
'COERCE_DECIMAL_TO_STRING': False, 'COERCE_DECIMAL_TO_STRING': False,
'EXCEPTION_HANDLER':
'superevents.api.exceptions.gracedb_exception_handler',
} }
# Location of packages installed by bower # Location of packages installed by bower
......
...@@ -8,11 +8,14 @@ def gracedb_exception_handler(exc, context): ...@@ -8,11 +8,14 @@ def gracedb_exception_handler(exc, context):
# to get the standard error response. # to get the standard error response.
response = exception_handler(exc, context) response = exception_handler(exc, context)
# Now add the HTTP status code to the response. # Combine values into one list
if response is not None: exc_out = [item for sublist in exc.detail.values() for item in sublist]
if response.data.has_key('detail'):
response.data['detail'] = [] # For only one exception, just print it rather than the list
for a in exc.args: if len(exc_out) == 1:
response.data['detail'].append(a) exc_out = exc_out[0]
# Update response data
response.data = exc_out
return response 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