|
115 | 115 | CONTENT_IMAGE = const(3)
|
116 | 116 |
|
117 | 117 |
|
| 118 | +class HttpError(Exception): |
| 119 | + """HTTP Specific Error""" |
| 120 | + |
| 121 | + |
118 | 122 | class Fake_Requests:
|
119 | 123 | """For faking 'requests' using a local file instead of the network."""
|
120 | 124 |
|
@@ -758,10 +762,25 @@ def wget(self, url, filename, *, chunk_size=12000):
|
758 | 762 |
|
759 | 763 | self.neo_status((100, 100, 0))
|
760 | 764 | r = requests.get(url, stream=True)
|
| 765 | + |
761 | 766 | headers = {}
|
762 | 767 | for title, content in r.headers.items():
|
763 | 768 | headers[title.lower()] = content
|
764 | 769 |
|
| 770 | + if r.status_code == 200: |
| 771 | + print("Reply is OK!") |
| 772 | + self.neo_status((0, 0, 100)) # green = got data |
| 773 | + else: |
| 774 | + if self._debug: |
| 775 | + if "content-length" in headers: |
| 776 | + print("Content-Length: {}".format(int(headers["content-length"]))) |
| 777 | + if "date" in headers: |
| 778 | + print("Date: {}".format(headers["date"])) |
| 779 | + self.neo_status((100, 0, 0)) # red = http error |
| 780 | + raise HttpError( |
| 781 | + "Code {}: {}".format(r.status_code, r.reason.decode("utf-8")) |
| 782 | + ) |
| 783 | + |
765 | 784 | if self._debug:
|
766 | 785 | print(headers)
|
767 | 786 | if "content-length" in headers:
|
@@ -946,8 +965,8 @@ def fetch(self, refresh_url=None, timeout=10):
|
946 | 965 | if "date" in headers:
|
947 | 966 | print("Date: {}".format(headers["date"]))
|
948 | 967 | self.neo_status((100, 0, 0)) # red = http error
|
949 |
| - raise OSError( |
950 |
| - "HTTP {}: {}".format(r.status_code, r.reason.decode("utf-8")) |
| 968 | + raise HttpError( |
| 969 | + "Code {}: {}".format(r.status_code, r.reason.decode("utf-8")) |
951 | 970 | )
|
952 | 971 |
|
953 | 972 | if self._debug and content_type == CONTENT_TEXT:
|
|
0 commit comments