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
+13 -3
View File
@@ -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('/<path:path>', 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)
+13 -3
View File
@@ -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('/<path:path>', 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)