Return 429 on QuotaExceeded exception

This commit is contained in:
Maksym Pavlenko
2019-05-12 13:32:05 -07:00
parent 44292ffa41
commit 439883a6ad
+16 -8
View File
@@ -37,15 +37,23 @@ url_formats = {
def handler(event, lambda_context):
feed_id, video_id = _get_ids(event.get('path'))
redirect_url = download(feed_id, video_id)
return {
'statusCode': 302,
'statusDescription': '302 Found',
'headers': {
'Location': redirect_url,
try:
feed_id, video_id = _get_ids(event.get('path'))
redirect_url = download(feed_id, video_id)
return {
'statusCode': 302,
'statusDescription': '302 Found',
'headers': {
'Location': redirect_url,
}
}
except QuotaExceeded:
return {
'statusCode': 429,
'statusDescription': '429 Too Many Requests',
'body': 'Too many requests. Daily limit is 1000. Consider upgrading account to get unlimited access',
'headers': {'Content-Type': 'text/plain'}
}
}
def _get_ids(path):