akamhy / waybackpy

Wayback Machine API interface & a command-line tool
https://pypi.org/project/waybackpy/
MIT License
476 stars 33 forks source link

Raise WaybackError from URLError and include URL #19

Closed AntiCompositeNumber closed 4 years ago

AntiCompositeNumber commented 4 years ago

Changes

Traceback (most recent call last):
  File "/home/ac/git/waybackpy/waybackpy/wrapper.py", line 109, in get_response
    response = urlopen(req) #nosec
...
urllib.error.HTTPError: HTTP Error 404: NOT FOUND

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/ac/git/waybackpy/waybackpy/wrapper.py", line 67, in save
    header = self.get_response(req).headers
  File "/home/ac/git/waybackpy/waybackpy/wrapper.py", line 111, in get_response
    raise WaybackError(e)
waybackpy.exceptions.WaybackError: HTTP Error 404: NOT FOUND

to

Traceback (most recent call last):
  File "/home/ac/git/waybackpy/waybackpy/wrapper.py", line 109, in get_response
    response = urlopen(req) #nosec
 ...
urllib.error.HTTPError: HTTP Error 404: NOT FOUND

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/ac/git/waybackpy/waybackpy/wrapper.py", line 67, in save
    header = self.get_response(req).headers
  File "/home/ac/git/waybackpy/waybackpy/wrapper.py", line 111, in get_response
    raise WaybackError("Error while retrieving %s" % req.full_url) from e
waybackpy.exceptions.WaybackError: Error while retrieving https://web.archive.org/save/https://example.com

This provides more information (what URL caused the error) and accurately says that the exception in urlopen caused the WaybackError, not that they happened to both occur.

codecov[bot] commented 4 years ago

Codecov Report

Merging #19 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #19   +/-   ##
=======================================
  Coverage   98.85%   98.85%           
=======================================
  Files           1        1           
  Lines          87       87           
=======================================
  Hits           86       86           
  Misses          1        1           
Impacted Files Coverage Δ
tests/test_1.py 98.85% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update be7642c...c291cbd. Read the comment docs.