Improve error handling
This commit is contained in:
@@ -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"]
|
||||||
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("/", 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)
|
||||||
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:
|
else:
|
||||||
return "invalid url", 400
|
return "Invalid URL", 400
|
||||||
|
|
||||||
app.run(debug=False)
|
app.run(debug=False)
|
||||||
|
|||||||
+13
-3
@@ -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"]
|
||||||
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("/", 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('/')
|
||||||
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:
|
else:
|
||||||
return "invalid url", 400
|
return "Invalid URL", 400
|
||||||
|
|
||||||
|
|
||||||
app.run(debug=False)
|
app.run(debug=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user