From f36df714320e16a9ec4ba6dc778263b2092662c9 Mon Sep 17 00:00:00 2001 From: Mikhail Korobov Date: Tue, 30 May 2023 19:24:35 +0500 Subject: [PATCH] support non-standard status codes --- web_poet/page_inputs/client.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/web_poet/page_inputs/client.py b/web_poet/page_inputs/client.py index 6b3b6981..2478231a 100644 --- a/web_poet/page_inputs/client.py +++ b/web_poet/page_inputs/client.py @@ -90,8 +90,8 @@ def _handle_status( ): return - status = HTTPStatus(response.status) - msg = f"{response.status} {status.name} response for {response.url}" + status_name = _http_status_name(response.status) + msg = f"{response.status} {status_name} response for {response.url}" raise HttpResponseError(msg, request=request, response=response) async def request( @@ -265,3 +265,18 @@ async def batch_execute( def get_saved_responses(self) -> Iterable[_SavedResponseData]: """Return saved requests and responses.""" return self._saved_responses.values() + + +def _http_status_name(status: int): + """ + >>> _http_status_name(200) + 'OK' + >>> _http_status_name(404) + 'NOT_FOUND' + >>> _http_status_name(999) + 'UNKNOWN' + """ + try: + return HTTPStatus(status).name + except ValueError: + return "UNKNOWN"