diff --git a/src/poetry/publishing/uploader.py b/src/poetry/publishing/uploader.py
index c76ed052520..928edc855e1 100644
--- a/src/poetry/publishing/uploader.py
+++ b/src/poetry/publishing/uploader.py
@@ -8,8 +8,6 @@
from poetry.core.masonry.metadata import Metadata
from poetry.core.masonry.utils.helpers import distribution_name
-from requests.exceptions import ConnectionError
-from requests.exceptions import HTTPError
from requests_toolbelt import user_agent
from requests_toolbelt.multipart import MultipartEncoder
from requests_toolbelt.multipart import MultipartEncoderMonitor
@@ -27,23 +25,7 @@
class UploadError(Exception):
- def __init__(self, error: ConnectionError | HTTPError | str) -> None:
- if isinstance(error, HTTPError):
- if error.response is None:
- message = "HTTP Error connecting to the repository"
- else:
- message = (
- f"HTTP Error {error.response.status_code}: "
- f"{error.response.reason} | {error.response.content!r}"
- )
- elif isinstance(error, ConnectionError):
- message = (
- "Connection Error: We were unable to connect to the repository, "
- "ensure the url is correct and can be reached."
- )
- else:
- message = error
- super().__init__(message)
+ pass
class Uploader:
@@ -268,12 +250,22 @@ def _upload_file(
bar.display()
else:
resp.raise_for_status()
- except (requests.ConnectionError, requests.HTTPError) as e:
+
+ except requests.RequestException as e:
if self._io.output.is_decorated():
self._io.overwrite(
f" - Uploading {file.name} FAILED>"
)
- raise UploadError(e)
+
+ if e.response is not None:
+ message = (
+ f"HTTP Error {e.response.status_code}: "
+ f"{e.response.reason} | {e.response.content!r}"
+ )
+ raise UploadError(message) from e
+
+ raise UploadError("Error connecting to repository") from e
+
finally:
self._io.write_line("")
diff --git a/tests/console/commands/test_publish.py b/tests/console/commands/test_publish.py
index 78216936409..ca841ad7392 100644
--- a/tests/console/commands/test_publish.py
+++ b/tests/console/commands/test_publish.py
@@ -10,7 +10,6 @@
import requests
from poetry.factory import Factory
-from poetry.publishing.uploader import UploadError
if TYPE_CHECKING:
@@ -82,9 +81,7 @@ def request_callback(*_: Any, **__: Any) -> None:
assert exit_code == 1
- expected = str(UploadError(error=requests.ConnectionError()))
-
- assert expected in app_tester.io.fetch_error()
+ assert "Error connecting to repository" in app_tester.io.fetch_error()
def test_publish_with_cert(