|
5 | 5 | import importlib
|
6 | 6 | import inspect
|
7 | 7 | import itertools
|
| 8 | +from json import JSONDecodeError |
8 | 9 | import logging
|
9 | 10 | import os
|
10 | 11 | import platform
|
@@ -139,22 +140,29 @@ def await_results(commit_hash, slug, pings=45, sleep=2):
|
139 | 140 | {pings} pings and waiting {sleep} seconds between pings.
|
140 | 141 | """
|
141 | 142 |
|
142 |
| - for _i in range(pings): |
143 |
| - # Query for check results. |
144 |
| - res = requests.get(f"https://submit.cs50.io/api/results/check50", params={"commit_hash": commit_hash, "slug": slug}) |
145 |
| - results = res.json() |
| 143 | + try: |
| 144 | + for _i in range(pings): |
| 145 | + # Query for check results. |
| 146 | + res = requests.get(f"https://submit.cs50.io/api/results/check50", params={"commit_hash": commit_hash, "slug": slug}) |
| 147 | + results = res.json() |
146 | 148 |
|
147 |
| - if res.status_code not in [404, 200]: |
148 |
| - raise _exceptions.RemoteCheckError(results) |
| 149 | + if res.status_code not in [404, 200]: |
| 150 | + raise _exceptions.RemoteCheckError(results) |
149 | 151 |
|
150 |
| - if res.status_code == 200 and results["received_at"] is not None: |
151 |
| - break |
152 |
| - time.sleep(sleep) |
153 |
| - else: |
154 |
| - # Terminate if no response |
| 152 | + if res.status_code == 200 and results["received_at"] is not None: |
| 153 | + break |
| 154 | + time.sleep(sleep) |
| 155 | + else: |
| 156 | + # Terminate if no response |
| 157 | + raise _exceptions.Error( |
| 158 | + _("check50 is taking longer than normal!\n" |
| 159 | + "See https://submit.cs50.io/check50/{} for more detail").format(commit_hash)) |
| 160 | + |
| 161 | + except JSONDecodeError: |
| 162 | + # Invalid JSON object received from submit.cs50.io |
155 | 163 | raise _exceptions.Error(
|
156 |
| - _("check50 is taking longer than normal!\n" |
157 |
| - "See https://submit.cs50.io/check50/{} for more detail").format(commit_hash)) |
| 164 | + _("Sorry, something's wrong, please try again.\n" |
| 165 | + "If the problem persists, please visit our status page https://cs50.statuspage.io for more information.")) |
158 | 166 |
|
159 | 167 | if not results["check50"]:
|
160 | 168 | raise _exceptions.RemoteCheckError(results)
|
|
0 commit comments