Skip to content

Commit

Permalink
feat: error response
Browse files Browse the repository at this point in the history
  • Loading branch information
xyb committed Aug 14, 2023
1 parent bb97d5a commit e316603
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions task/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,9 @@ class FullDownloadNowSerializer(serializers.Serializer):
full_download_now = serializers.BooleanField()


class ErrorSerializer(serializers.Serializer):
error = serializers.CharField()


class OperationSerializer(serializers.Serializer):
pass
3 changes: 3 additions & 0 deletions task/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .leecher import transfer
from .models import Task
from .serializers import CaptchaCodeSerializer
from .serializers import ErrorSerializer
from .serializers import FullDownloadNowSerializer
from .serializers import OperationSerializer
from .serializers import TaskSerializer
Expand Down Expand Up @@ -89,6 +90,7 @@ def captcha(self, request: HttpRequest, pk: int = None) -> HttpResponse:
task = self.get_object()
return HttpResponse(BytesIO(task.captcha), content_type=JPEGRenderer.media_type)

@extend_schema(responses={200: TaskSerializer, 400: ErrorSerializer, 404: None})
@action(methods=["post"], detail=True, name="Input Captcha Code")
def captcha_code(self, request: HttpRequest, pk: int = None) -> HttpResponse:
serializer = CaptchaCodeSerializer(data=request.data)
Expand Down Expand Up @@ -140,6 +142,7 @@ def resume(self, request: HttpRequest, pk: int = None) -> HttpResponse:
task.schedule_resume()
return Response({"status": task.status})

@extend_schema(responses={204: None, 400: ErrorSerializer, 404: None})
@action(methods=["delete"], detail=True, name="Erase task, remote and local files")
def erase(self, request: HttpRequest, pk: int = None) -> HttpResponse:
task = self.get_object()
Expand Down

0 comments on commit e316603

Please sign in to comment.