mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-04 19:30:13 +00:00
implement api return status code
This commit is contained in:
parent
52a54fbe31
commit
8d5b4ac242
@ -40,7 +40,11 @@ class ApiBaseView(APIView):
|
|||||||
url = f"{es_url}{self.search_base}{document_id}"
|
url = f"{es_url}{self.search_base}{document_id}"
|
||||||
print(url)
|
print(url)
|
||||||
response = requests.get(url, auth=self.context["es_auth"])
|
response = requests.get(url, auth=self.context["es_auth"])
|
||||||
self.response["data"] = response.json()["_source"]
|
try:
|
||||||
|
self.response["data"] = response.json()["_source"]
|
||||||
|
except KeyError:
|
||||||
|
print(f"item not found: {document_id}")
|
||||||
|
self.response["data"] = False
|
||||||
self.status_code = response.status_code
|
self.status_code = response.status_code
|
||||||
|
|
||||||
def get_paginate(self):
|
def get_paginate(self):
|
||||||
@ -70,7 +74,7 @@ class VideoApiView(ApiBaseView):
|
|||||||
"""get request"""
|
"""get request"""
|
||||||
self.config_builder()
|
self.config_builder()
|
||||||
self.get_document(video_id)
|
self.get_document(video_id)
|
||||||
return Response(self.response)
|
return Response(self.response, status=self.status_code)
|
||||||
|
|
||||||
|
|
||||||
class ChannelApiView(ApiBaseView):
|
class ChannelApiView(ApiBaseView):
|
||||||
@ -85,7 +89,7 @@ class ChannelApiView(ApiBaseView):
|
|||||||
"""get request"""
|
"""get request"""
|
||||||
self.config_builder()
|
self.config_builder()
|
||||||
self.get_document(channel_id)
|
self.get_document(channel_id)
|
||||||
return Response(self.response)
|
return Response(self.response, status=self.status_code)
|
||||||
|
|
||||||
|
|
||||||
class PlaylistApiView(ApiBaseView):
|
class PlaylistApiView(ApiBaseView):
|
||||||
@ -100,7 +104,7 @@ class PlaylistApiView(ApiBaseView):
|
|||||||
"""get request"""
|
"""get request"""
|
||||||
self.config_builder()
|
self.config_builder()
|
||||||
self.get_document(playlist_id)
|
self.get_document(playlist_id)
|
||||||
return Response(self.response)
|
return Response(self.response, status=self.status_code)
|
||||||
|
|
||||||
|
|
||||||
class DownloadApiView(ApiBaseView):
|
class DownloadApiView(ApiBaseView):
|
||||||
@ -115,7 +119,7 @@ class DownloadApiView(ApiBaseView):
|
|||||||
"""get request"""
|
"""get request"""
|
||||||
self.config_builder()
|
self.config_builder()
|
||||||
self.get_document(video_id)
|
self.get_document(video_id)
|
||||||
return Response(self.response)
|
return Response(self.response, status=self.status_code)
|
||||||
|
|
||||||
|
|
||||||
class DownloadApiListView(ApiBaseView):
|
class DownloadApiListView(ApiBaseView):
|
||||||
|
Loading…
Reference in New Issue
Block a user