Skip to content

Commit

Permalink
URLFile: exception type for failed requests (commaai#30330)
Browse files Browse the repository at this point in the history
URLFileException for URLFile request errors
  • Loading branch information
fredyshox authored Oct 25, 2023
1 parent 4094d58 commit c27e977
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tools/lib/url_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def hash_256(link):
return hsh


class URLFileException(Exception):
pass


class URLFile:
_tlocal = threading.local()

Expand Down Expand Up @@ -158,11 +162,11 @@ def test(debug_type, debug_msg):

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)
Expand Down

0 comments on commit c27e977

Please sign in to comment.