Give a proper error message for 429 errors

These occur when too many requests are coming from a Tor exit node.
Before, there would be an error page with an exception instructing users to report the issue.
But this is an expected and persistent issue.
This commit is contained in:
James Taylor
2020-01-31 20:06:15 -08:00
parent cd4a2fb0eb
commit f787e4e202
6 changed files with 49 additions and 3 deletions

View File

@@ -1,6 +1,8 @@
from youtube import util
import flask
import settings
import traceback
from sys import exc_info
yt_app = flask.Flask(__name__)
yt_app.url_map.strict_slashes = False
@@ -34,4 +36,14 @@ def commatize(num):
@yt_app.errorhandler(500)
def error_page(e):
if (exc_info()[0] == util.FetchError
and exc_info()[1].code == '429'
and settings.route_tor
):
error_message = ('Error: Youtube blocked the request because the Tor'
' exit node is overcrowded. Try getting a new exit node by'
' restarting the Tor Browser.')
if exc_info()[1].ip:
error_message += ' Exit node IP address: ' + exc_info()[1].ip
return flask.render_template('error.html', error_message=error_message), 502
return flask.render_template('error.html', traceback=traceback.format_exc()), 500