Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
AURA
steering
Commits
38bc37e5
Verified
Commit
38bc37e5
authored
1 year ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
feat: catch integrity errors and return an error code and message
Closes:
#188
parent
b1e797a8
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#7410
passed
1 year ago
Stage: build
Stage: deploy
Stage: release
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/views.py
+19
-3
19 additions, 3 deletions
program/views.py
with
19 additions
and
3 deletions
program/views.py
+
19
−
3
View file @
38bc37e5
...
...
@@ -34,6 +34,7 @@ from rest_framework.response import Response
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.db
import
IntegrityError
from
django.http
import
Http404
,
HttpResponse
,
JsonResponse
from
django.shortcuts
import
get_object_or_404
from
django.utils
import
timezone
...
...
@@ -383,7 +384,15 @@ class APIShowViewSet(DisabledObjectPermissionCheckMixin, viewsets.ModelViewSet):
)
if
serializer
.
is_valid
(
raise_exception
=
True
):
serializer
.
save
()
try
:
serializer
.
save
()
except
IntegrityError
:
data
=
{
"
slug
"
:
{
"
code
"
:
"
unique
"
,
"
message
"
:
"
show with this slug already exists.
"
}
}
return
Response
(
data
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_201_CREATED
)
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -398,8 +407,15 @@ class APIShowViewSet(DisabledObjectPermissionCheckMixin, viewsets.ModelViewSet):
)
if
serializer
.
is_valid
(
raise_exception
=
True
):
serializer
.
save
()
return
Response
(
serializer
.
data
)
try
:
serializer
.
save
()
return
Response
(
serializer
.
data
)
except
IntegrityError
:
data
=
{
"
slug
"
:
{
"
code
"
:
"
unique
"
,
"
message
"
:
"
show with this slug already exists.
"
}
}
return
Response
(
data
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
def
partial_update
(
self
,
request
,
*
args
,
**
kwargs
):
kwargs
[
"
partial
"
]
=
True
...
...
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