From 6f51ee82670ba122f45d9232f843514af8650fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20R=C4=85czy?= Date: Wed, 25 Oct 2023 16:20:12 -0700 Subject: [PATCH] URLFile: exception type for failed requests (#30330) URLFileException for URLFile request errors old-commit-hash: c27e977475e33e19c8042dfead745f5cbc1ad9ee --- tools/lib/url_file.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/lib/url_file.py b/tools/lib/url_file.py index 2f933e3b7f..315ade514b 100644 --- a/tools/lib/url_file.py +++ b/tools/lib/url_file.py @@ -17,6 +17,10 @@ def hash_256(link): return hsh +class URLFileException(Exception): + pass + + class URLFile: _tlocal = threading.local() @@ -158,11 +162,11 @@ class URLFile: response_code = c.getinfo(pycurl.RESPONSE_CODE) if response_code == 416: # Requested Range Not Satisfiable - raise Exception(f"Error, range out of bounds {response_code} {headers} ({self._url}): {repr(dats.getvalue())[:500]}") + raise URLFileException(f"Error, range out of bounds {response_code} {headers} ({self._url}): {repr(dats.getvalue())[:500]}") if download_range and response_code != 206: # Partial Content - raise Exception(f"Error, requested range but got unexpected response {response_code} {headers} ({self._url}): {repr(dats.getvalue())[:500]}") + raise URLFileException(f"Error, requested range but got unexpected response {response_code} {headers} ({self._url}): {repr(dats.getvalue())[:500]}") if (not download_range) and response_code != 200: # OK - raise Exception(f"Error {response_code} {headers} ({self._url}): {repr(dats.getvalue())[:500]}") + raise URLFileException(f"Error {response_code} {headers} ({self._url}): {repr(dats.getvalue())[:500]}") ret = dats.getvalue() self._pos += len(ret)