Skip to content

Commit ae0a7d3

Browse files
authored
Apply suggestions from code review
1 parent 19c89e7 commit ae0a7d3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

pyiceberg/catalog/rest/response.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,16 @@ def _handle_non_200_response(exc: HTTPError, error_handler: dict[int, type[Excep
101101
response += f": {description}"
102102
if uri := error.error_uri:
103103
response += f" ({uri})"
104+
elif not exc.response.text:
105+
try:
106+
phrase = HTTPStatus(code).phrase
107+
except ValueError:
108+
phrase = exc.response.reason or f"HTTP {code}"
109+
response = f"{exception.__name__}: RestError: {phrase}"
104110
else:
105-
# Handle empty response bodies (Specifically HEAD requests via exist requests)
106-
if not exc.response.text:
107-
http_status = HTTPStatus(code)
108-
response = f"{exception.__name__}: RestError: {http_status.phrase}"
109-
else:
110-
error = ErrorResponse.model_validate_json(exc.response.text).error
111-
response = f"{error.type}: {error.message}"
111+
else:
112+
error = ErrorResponse.model_validate_json(exc.response.text).error
113+
response = f"{error.type}: {error.message}"
112114
except JSONDecodeError:
113115
# In the case we don't have a proper response
114116
response = f"RESTError {exc.response.status_code}: Could not decode json payload: {exc.response.text}"

0 commit comments

Comments
 (0)