Improve error handling

This commit is contained in:
Wasi Master
2023-06-01 09:28:06 +06:00
parent b42098cce0
commit d4b373ada5
2 changed files with 26 additions and 6 deletions
+11 -1
View File
@@ -25,7 +25,12 @@ def main_page():
@app.route("/article", methods=["POST"]) @app.route("/article", methods=["POST"])
def show_article(): def show_article():
link = flask.request.form["link"] link = flask.request.form["link"]
try:
return bypass_paywall(link) return bypass_paywall(link)
except requests.exceptions.RequestException as e:
return str(e), 400
except e:
raise e
@app.route("/", defaults={"path": ""}) @app.route("/", defaults={"path": ""})
@app.route('/<path:path>', methods=["GET"]) @app.route('/<path:path>', methods=["GET"])
@@ -36,8 +41,13 @@ def get_article(path):
if len(parts) >= 5: if len(parts) >= 5:
actual_url = 'https://' + parts[4].lstrip('/') actual_url = 'https://' + parts[4].lstrip('/')
print(actual_url) print(actual_url)
try:
return bypass_paywall(actual_url) return bypass_paywall(actual_url)
except requests.exceptions.RequestException as e:
return str(e), 400
except e:
raise e
else: else:
return "invalid url", 400 return "Invalid URL", 400
app.run(debug=False) app.run(debug=False)
+11 -1
View File
@@ -106,7 +106,12 @@ def main_page():
@app.route("/article", methods=["POST"]) @app.route("/article", methods=["POST"])
def show_article(): def show_article():
link = flask.request.form["link"] link = flask.request.form["link"]
try:
return bypass_paywall(link) return bypass_paywall(link)
except requests.exceptions.RequestException as e:
return str(e), 400
except e:
raise e
@app.route("/", defaults={"path": ""}) @app.route("/", defaults={"path": ""})
@app.route('/<path:path>', methods=["GET"]) @app.route('/<path:path>', methods=["GET"])
@@ -115,9 +120,14 @@ def get_article(path):
parts = full_url.split('/',4) parts = full_url.split('/',4)
if len(parts) >= 5: if len(parts) >= 5:
actual_url = 'https://' + parts[4].lstrip('/') actual_url = 'https://' + parts[4].lstrip('/')
try:
return bypass_paywall(actual_url) return bypass_paywall(actual_url)
except requests.exceptions.RequestException as e:
return str(e), 400
except e:
raise e
else: else:
return "invalid url", 400 return "Invalid URL", 400
app.run(debug=False) app.run(debug=False)