Handle more gracefully when video/clip not found

This commit is contained in:
Ivan Habunek 2020-08-09 11:55:40 +02:00
parent 78295a492c
commit 4edf299780
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
2 changed files with 6 additions and 1 deletions

View File

@ -219,6 +219,9 @@ def _download_clip(slug, args):
print_out("<dim>Looking up clip...</dim>")
clip = twitch.get_clip(slug)
if not clip:
raise ConsoleError("Clip '{}' not found".format(slug))
print_out("Found: <green>{}</green> by <yellow>{}</yellow>, playing <blue>{}</blue> ({})".format(
clip["title"],
clip["broadcaster"]["displayName"],

View File

@ -18,8 +18,10 @@ def authenticated_get(url, params={}, headers={}):
headers['Client-ID'] = CLIENT_ID
response = requests.get(url, params, headers=headers)
if response.status_code == 400:
if 400 <= response.status_code < 500:
data = response.json()
# TODO: this does not look nice in the console since data["message"]
# can contain a JSON encoded object.
raise ConsoleError(data["message"])
response.raise_for_status()