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()
statuses = get_account_tagged_statuses(id) try:
statuses = get_account_tagged_statuses(id)
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)
return render_template('_tag.html', threads=statuses, tag=id, app=app, attribution=attribution, render_date=datetime.now())
@threads.route('/thread/<path:id>') @threads.route('/thread/<path:id>')
@ -169,15 +173,19 @@ def tag(id):
def thread(id): def thread(id):
attribution = get_attribution() attribution = get_attribution()
app = get_app_config() app = get_app_config()
max_length = app.get('max_summary_length', 69) # Configure max summary length try:
status = fetch_thread(id) max_length = app.get('max_summary_length', 69) # Configure max summary length
if status is not None: status = fetch_thread(id)
status['summary'] = utils.clean_html(status['content']).strip() if status is not None:
if len(status['summary']) > max_length: status['summary'] = utils.clean_html(status['content']).strip()
status['summary'] = status['summary'][:max_length] + '...' if len(status['summary']) > max_length:
return render_template('_home.html', threads=[status], app=app, attribution=attribution, render_date=datetime.now()) status['summary'] = status['summary'][:max_length] + '...'
else: return render_template('_home.html', threads=[status], app=app, attribution=attribution, render_date=datetime.now())
return redirect(url_for('threads.home')) else:
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)