Skip to content
Snippets Groups Projects
Commit 3c18fdb9 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[toolchains][api] Improve exception raising

parent f3afcdbe
No related branches found
No related tags found
1 merge request!327Refactor update creation api
......@@ -34,9 +34,8 @@ from django.core.exceptions import ValidationError
from rest_framework.response import Response
from rest_framework import serializers
from rest_framework.exceptions import PermissionDenied, ParseError
from rest_framework import exceptions as drf_exceptions
from ..common.responses import BadRequestResponse
from ..common.api import (
CheckContributionNameView,
ShareView,
......@@ -118,13 +117,10 @@ class RetrieveUpdateDestroyToolchainsView(RetrieveUpdateDestroyContributionView)
model = Toolchain
serializer_class = FullToolchainSerializer
def put(self, request, author_name, object_name, version=None):
if version is None:
return BadRequestResponse("A version number must be provided")
def put(self, request, author_name, object_name, version):
try:
data = request.data
except ParseError as e:
except drf_exceptions.ParseError as e:
raise serializers.ValidationError({"data": str(e)})
else:
if not data:
......@@ -229,7 +225,7 @@ class RetrieveUpdateDestroyToolchainsView(RetrieveUpdateDestroyContributionView)
# Check that the object can still be modified (if applicable, the
# documentation can always be modified)
if declaration is not None and not dbtoolchain.modifiable():
raise PermissionDenied(
raise drf_exceptions.PermissionDenied(
"The {} isn't modifiable anymore (either shared with someone else, or needed by an attestation)".format(
dbtoolchain.model_name()
)
......@@ -263,7 +259,7 @@ class RetrieveUpdateDestroyToolchainsView(RetrieveUpdateDestroyContributionView)
try:
dbtoolchain.save()
except Exception as e:
return BadRequestResponse(str(e))
raise drf_exceptions.APIException(str(e))
# Nothing to return?
if len(fields_to_return) == 0:
......
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