File tree 2 files changed +29
-3
lines changed
2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 6
6
from requests .utils import parse_header_links
7
7
8
8
from .exceptions import (
9
+ BadGateway ,
9
10
BlockedByRobots ,
10
11
CachedPage ,
12
+ Forbidden ,
11
13
TooManyRequests ,
14
+ UnknownError ,
12
15
WaybackRuntimeError ,
13
16
)
14
17
@@ -50,10 +53,15 @@ def capture(
50
53
raise WaybackRuntimeError (error_header )
51
54
52
55
# 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 :
56
60
raise TooManyRequests (response .headers )
61
+ elif status_code == 502 :
62
+ raise BadGateway (response .headers )
63
+ elif status_code == 520 :
64
+ raise UnknownError (response .headers )
57
65
58
66
# If there's a content-location header in the response, we will use that.
59
67
try :
Original file line number Diff line number Diff line change @@ -16,7 +16,25 @@ class BlockedByRobots(WaybackRuntimeError):
16
16
pass
17
17
18
18
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
+
19
31
class TooManyRequests (WaybackRuntimeError ):
20
32
"""Raised when archive.org when you have exceeded its throttle on request frequency. Slow it down."""
21
33
22
34
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
You can’t perform that action at this time.
0 commit comments