From 47e6c46d32d7137764a3f920dbd77ffe0f51dd6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20N=C3=B8rgaard?= Date: Wed, 4 Dec 2024 02:22:45 +0000 Subject: [PATCH] special case errror for id being of the older api spec --- hondana/errors.py | 28 ++++++++++++++++++++++++++++ hondana/http.py | 3 +++ 2 files changed, 31 insertions(+) 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: