Skip to content

Commit

Permalink
Allow for an HttpError without a response (#1023)
Browse files Browse the repository at this point in the history
* Allow for an HttpError without a response

* FIx formatting

* Lower coverage threshold

* Use "no cover" instead of lower threshold

* Use cast instead of guard
  • Loading branch information
bhrutledge committed Oct 22, 2023
1 parent afc37f8 commit 88245fc
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions twine/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import http
import logging
import sys
from typing import Any
from typing import Any, cast

import requests

Expand All @@ -32,13 +32,16 @@ def main() -> Any:
try:
error = cli.dispatch(sys.argv[1:])
except requests.HTTPError as exc:
# Assuming this response will never be None
response = cast(requests.Response, exc.response)

error = True
status_code = exc.response.status_code
status_code = response.status_code
status_phrase = http.HTTPStatus(status_code).phrase
logger.error(
f"{exc.__class__.__name__}: {status_code} {status_phrase} "
f"from {exc.response.url}\n"
f"{exc.response.reason}"
f"from {response.url}\n"
f"{response.reason}"
)
except exceptions.TwineException as exc:
error = True
Expand Down

0 comments on commit 88245fc

Please sign in to comment.