Improve error handling
This commit is contained in:
@@ -25,7 +25,12 @@ def main_page():
|
||||
@app.route("/article", methods=["POST"])
|
||||
def show_article():
|
||||
link = flask.request.form["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)
|
||||
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)
|
||||
|
||||
+11
-1
@@ -106,7 +106,12 @@ def main_page():
|
||||
@app.route("/article", methods=["POST"])
|
||||
def show_article():
|
||||
link = flask.request.form["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('/')
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user