2222
2323from poetry .__version__ import __version__
2424from poetry .config .config import Config
25+ from poetry .console .exceptions import ConsoleMessage
26+ from poetry .console .exceptions import PoetryRuntimeError
2527from poetry .exceptions import PoetryError
2628from poetry .utils .constants import REQUESTS_TIMEOUT
2729from poetry .utils .constants import RETRY_AFTER_HEADER
@@ -230,7 +232,28 @@ def request(
230232 resp = session .send (prepared_request , ** send_kwargs )
231233 except (requests .exceptions .ConnectionError , OSError ) as e :
232234 if is_last_attempt :
233- raise e
235+ parsed_url = urllib .parse .urlsplit (url )
236+ exc = PoetryRuntimeError .create (
237+ reason = f"<error>All attempts to connect to <c1>{ parsed_url .netloc } </> failed.</>" ,
238+ exception = e ,
239+ )
240+ exc .append (
241+ ConsoleMessage (
242+ "the server is not responding to requests at the moment\n "
243+ "the hostname cannot be resolved by your DNS\n "
244+ "your network is not connected to the internet\n "
245+ )
246+ .indent (" - " )
247+ .make_section ("Probable Causes" )
248+ .wrap ("warning" )
249+ )
250+ exc .append (
251+ ConsoleMessage (
252+ f"<b>Note:</> The path requested was <c1>{ parsed_url .path } </>." ,
253+ debug = True ,
254+ )
255+ )
256+ raise exc
234257 else :
235258 if resp .status_code not in STATUS_FORCELIST or is_last_attempt :
236259 if raise_for_status :
@@ -245,7 +268,7 @@ def request(
245268 continue
246269
247270 # this should never really be hit under any sane circumstance
248- raise PoetryError ("Failed HTTP {} request" , method .upper ())
271+ raise PoetryError (f "Failed HTTP request: { method .upper ()} { url } " )
249272
250273 def _get_backoff (self , response : requests .Response | None , attempt : int ) -> float :
251274 if response is not None :
0 commit comments