diff --git a/fdc/views.py b/fdc/views.py index 1e3fc54..1dbff50 100644 --- a/fdc/views.py +++ b/fdc/views.py @@ -1,5 +1,5 @@ -from drf_spectacular.utils import extend_schema -from rest_framework import decorators, response, viewsets +from drf_spectacular.utils import extend_schema, inline_serializer +from rest_framework import decorators, response, serializers, status, viewsets from fdc.models import AttestationResult @@ -35,7 +35,15 @@ def list(self, request, *args, **kwargs): @extend_schema( request=AttestationTypeGetByRoundIdBytesRequest, - responses=AttestationMinimalProofSerializer, + responses={ + 200: AttestationMinimalProofSerializer, + 400: inline_serializer( + "AttestationTypeGetByRoundIdBytesErrorSerializer", + fields={ + "error": serializers.CharField(), + }, + ), + }, ) @decorators.action( detail=False, methods=["post"], url_path="get-proof-round-id-bytes" @@ -47,10 +55,16 @@ def get_proof_round_id_bytes(self, request, *args, **kwargs): _body.is_valid(raise_exception=True) body = _body.validated_data - obj = self.get_queryset().get( - voting_round_id=body["votingRoundId"], - request_hex=body["requestBytes"], - ) + try: + obj = self.get_queryset().get( + voting_round_id=body["votingRoundId"], + request_hex=body["requestBytes"], + ) + except AttestationResult.DoesNotExist: + return response.Response( + data={"error": "attestation request not found"}, + status=status.HTTP_400_BAD_REQUEST, + ) serializer = self.get_serializer(obj) diff --git a/ftso/views.py b/ftso/views.py index 9378ca9..4de2094 100644 --- a/ftso/views.py +++ b/ftso/views.py @@ -1,8 +1,8 @@ import logging -from drf_spectacular.utils import extend_schema +from drf_spectacular.utils import extend_schema, inline_serializer from py_flare_common.merkle import MerkleTree -from rest_framework import decorators, response, status, viewsets +from rest_framework import decorators, response, serializers, status, viewsets from ftso.models import FeedResult, RandomResult from ftso.serializers.data import ( @@ -55,7 +55,15 @@ def anchor_feed_names(self, request, *args, **kwargs): @extend_schema( parameters=[FeedResultFeedsWithProofsQuerySerializer], request=FeedResultFeedsWithProofsRequestSerializer, - responses={200: MerkleProofValueSerializer(many=True)}, + responses={ + 200: MerkleProofValueSerializer(many=True), + 400: inline_serializer( + "AttestationTypeGetByRoundIdBytesErrorSerializer", + fields={ + "error": serializers.CharField(), + }, + ), + }, ) @decorators.action( detail=False, methods=["post"], url_path="anchor-feeds-with-proof" @@ -87,7 +95,10 @@ def anchor_feeds_with_proof(self, request, *args, **kwargs): .all() ) if queryset is None: - return response.Response(None, status=status.HTTP_404_NOT_FOUND) + return response.Response( + data={"error": "anchor feeds not found"}, + status=status.HTTP_400_BAD_REQUEST, + ) tree = get_merkle_tree_for_round(voting_round_id) data = [