feat: error handling for routes tag & thread

This commit is contained in:
ayo 2026-06-06 20:18:29 +02:00
parent 8e95109995
commit ba31ff7e6f

View file

@ -159,9 +159,13 @@ def home():
def tag(id): def tag(id):
attribution = get_attribution() attribution = get_attribution()
app = get_app_config() app = get_app_config()
try:
statuses = get_account_tagged_statuses(id) statuses = get_account_tagged_statuses(id)
return render_template('_tag.html', threads=statuses, tag=id, app=app, attribution=attribution, render_date=datetime.now()) return render_template('_tag.html', threads=statuses, tag=id, app=app, attribution=attribution, render_date=datetime.now())
except ValueError as message:
return render_template('_error.html', app=app, attribution=attribution, render_date=datetime.now(), message=message)
@threads.route('/thread/<path:id>') @threads.route('/thread/<path:id>')
@ -169,6 +173,7 @@ def tag(id):
def thread(id): def thread(id):
attribution = get_attribution() attribution = get_attribution()
app = get_app_config() app = get_app_config()
try:
max_length = app.get('max_summary_length', 69) # Configure max summary length max_length = app.get('max_summary_length', 69) # Configure max summary length
status = fetch_thread(id) status = fetch_thread(id)
if status is not None: if status is not None:
@ -178,6 +183,9 @@ def thread(id):
return render_template('_home.html', threads=[status], app=app, attribution=attribution, render_date=datetime.now()) return render_template('_home.html', threads=[status], app=app, attribution=attribution, render_date=datetime.now())
else: else:
return redirect(url_for('threads.home')) return redirect(url_for('threads.home'))
except ValueError as message:
return render_template('_error.html', app=app, attribution=attribution, render_date=datetime.now(), message=message)
@threads.route('/api') @threads.route('/api')
@cache.cached(timeout=300) @cache.cached(timeout=300)