diff --git a/hondana/errors.py b/hondana/errors.py index 6809726..46ea600 100644 --- a/hondana/errors.py +++ b/hondana/errors.py @@ -38,6 +38,7 @@ "Forbidden", "MangaDexServerError", "NotFound", + "PreviousAPIVersionRequest", "RefreshTokenFailure", "Unauthorized", "UploadInProgress", @@ -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. diff --git a/hondana/http.py b/hondana/http.py index cc213c4..4da96ab 100755 --- a/hondana/http.py +++ b/hondana/http.py @@ -56,6 +56,7 @@ Forbidden, MangaDexServerError, NotFound, + PreviousAPIVersionRequest, RefreshTokenFailure, Unauthorized, ) @@ -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: