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"