Skip to content

Commit 810d457

Browse files
committed
Added more exceptions
1 parent be24955 commit 810d457

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

savepagenow/api.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
from requests.utils import parse_header_links
77

88
from .exceptions import (
9+
BadGateway,
910
BlockedByRobots,
1011
CachedPage,
12+
Forbidden,
1113
TooManyRequests,
14+
UnknownError,
1215
WaybackRuntimeError,
1316
)
1417

@@ -50,10 +53,15 @@ def capture(
5053
raise WaybackRuntimeError(error_header)
5154

5255
# If it has an error code, raise that
53-
if response.status_code in [403, 502, 520]:
54-
raise WaybackRuntimeError(response.headers)
55-
elif response.status_code == 429:
56+
status_code = response.status_code
57+
if status_code == 403:
58+
raise Forbidden(response.headers)
59+
elif status_code == 429:
5660
raise TooManyRequests(response.headers)
61+
elif status_code == 502:
62+
raise BadGateway(response.headers)
63+
elif status_code == 520:
64+
raise UnknownError(response.headers)
5765

5866
# If there's a content-location header in the response, we will use that.
5967
try:

savepagenow/exceptions.py

+18
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,25 @@ class BlockedByRobots(WaybackRuntimeError):
1616
pass
1717

1818

19+
class BadGateway(WaybackRuntimeError):
20+
"""Raised when archive.org when you receive a 502 bad gateway status code in response to your request."""
21+
22+
pass
23+
24+
25+
class Forbidden(WaybackRuntimeError):
26+
"""Raised when archive.org when you receive a 403 forbidden status code in response to your request."""
27+
28+
pass
29+
30+
1931
class TooManyRequests(WaybackRuntimeError):
2032
"""Raised when archive.org when you have exceeded its throttle on request frequency. Slow it down."""
2133

2234
pass
35+
36+
37+
class UnknownError(WaybackRuntimeError):
38+
"""Raised when archive.org when you receive a 520 unknown status code in response to your request."""
39+
40+
pass

0 commit comments

Comments
 (0)