Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GraceDB Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael Coughlin
GraceDB Server
Commits
ce9f2be9
Commit
ce9f2be9
authored
6 years ago
by
Tanner Prestegard
Committed by
GraceDB
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Trying to make API exceptions nicer
parent
6c745ad4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gracedb/superevents/api/exceptions.py
+12
-8
12 additions, 8 deletions
gracedb/superevents/api/exceptions.py
with
12 additions
and
8 deletions
gracedb/superevents/api/exceptions.py
+
12
−
8
View file @
ce9f2be9
import
logging
from
rest_framework.views
import
exception_handler
from
rest_framework.views
import
exception_handler
import
logg
ing
# Set up
logg
er
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
def
gracedb_exception_handler
(
exc
,
context
):
def
gracedb_exception_handler
(
exc
,
context
):
# Call REST framework's default exception handler first,
# Call REST framework's default exception handler first,
# to get the standard error response.
# to get the standard error response.
response
=
exception_handler
(
exc
,
context
)
response
=
exception_handler
(
exc
,
context
)
# Combine values into one list
if
hasattr
(
exc
,
'
detail
'
)
and
hasattr
(
exc
.
detail
,
'
values
'
):
exc_out
=
[
item
for
sublist
in
exc
.
detail
.
values
()
for
item
in
sublist
]
# 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
# For only one exception, just print it rather than the list
if
len
(
exc_out
)
==
1
:
if
len
(
exc_out
)
==
1
:
exc_out
=
exc_out
[
0
]
exc_out
=
exc_out
[
0
]
# Update response data
# Update response data
response
.
data
=
exc_out
response
.
data
=
exc_out
return
response
return
response
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment