Skip to content

Commit

Permalink
special case errror for id being of the older api spec
Browse files Browse the repository at this point in the history
  • Loading branch information
AbstractUmbra committed Dec 4, 2024
1 parent c1dd331 commit 47e6c46
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions hondana/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"Forbidden",
"MangaDexServerError",
"NotFound",
"PreviousAPIVersionRequest",
"RefreshTokenFailure",
"Unauthorized",
"UploadInProgress",
Expand Down Expand Up @@ -222,6 +223,33 @@ def __init__(self, response: aiohttp.ClientResponse, /, *, errors: list[ErrorTyp
super().__init__(response, status_code=400, errors=errors)


class PreviousAPIVersionRequest(BadRequest):
"""
An error for when the API query matches the criteria of an older API version.
Attributes
-----------
response: :class:`aiohttp.ClientResponse`
The response object pertaining to this request.
status_code: Literal[``400``]
The HTTP status code for this request.
response_id: :class:`str`
The UUID relating to this failed HTTP request.
This is to be used when contacting MangaDex about an error.
errors: List[:class:`~hondana.errors.Error`]
The list of errors returned from MangaDex.
"""

def __init__(self, response: aiohttp.ClientResponse, /) -> None:
super().__init__(response, errors=[])

def __str__(self) -> str:
return (
f"HTTP Status: {self.status_code} and response id: {self.response_id} :: "
"Your API request matches the critera for MangaDex API version <5."
)


class Unauthorized(APIException):
"""An error for when you are unauthorized on this API endpoint.
Expand Down
3 changes: 3 additions & 0 deletions hondana/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
Forbidden,
MangaDexServerError,
NotFound,
PreviousAPIVersionRequest,
RefreshTokenFailure,
Unauthorized,
)
Expand Down Expand Up @@ -513,6 +514,8 @@ async def request(
continue

if not isinstance(data, dict):
if isinstance(data, str):
raise PreviousAPIVersionRequest(response)
break # unreachable

if response.status == 400:
Expand Down

0 comments on commit 47e6c46

Please sign in to comment.