diff --git a/index.py b/index.py index 75eacc3..8f15d85 100644 --- a/index.py +++ b/index.py @@ -25,7 +25,12 @@ def main_page(): @app.route("/article", methods=["POST"]) def show_article(): link = flask.request.form["link"] - return bypass_paywall(link) + try: + return bypass_paywall(link) + except requests.exceptions.RequestException as e: + return str(e), 400 + except e: + raise e @app.route("/", defaults={"path": ""}) @app.route('/', methods=["GET"]) @@ -36,8 +41,13 @@ def get_article(path): if len(parts) >= 5: actual_url = 'https://' + parts[4].lstrip('/') print(actual_url) - return bypass_paywall(actual_url) + try: + return bypass_paywall(actual_url) + except requests.exceptions.RequestException as e: + return str(e), 400 + except e: + raise e else: - return "invalid url", 400 + return "Invalid URL", 400 app.run(debug=False) diff --git a/portable.py b/portable.py index f152c77..9f84c4b 100644 --- a/portable.py +++ b/portable.py @@ -106,7 +106,12 @@ def main_page(): @app.route("/article", methods=["POST"]) def show_article(): link = flask.request.form["link"] - return bypass_paywall(link) + try: + return bypass_paywall(link) + except requests.exceptions.RequestException as e: + return str(e), 400 + except e: + raise e @app.route("/", defaults={"path": ""}) @app.route('/', methods=["GET"]) @@ -115,9 +120,14 @@ def get_article(path): parts = full_url.split('/',4) if len(parts) >= 5: actual_url = 'https://' + parts[4].lstrip('/') - return bypass_paywall(actual_url) + try: + return bypass_paywall(actual_url) + except requests.exceptions.RequestException as e: + return str(e), 400 + except e: + raise e else: - return "invalid url", 400 + return "Invalid URL", 400 app.run(debug=False)