From 50fb34a131a762cbe4e7fe8e19e7eb9dd13aa249 Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Thu, 29 Aug 2024 12:57:13 +0300 Subject: Handle errors correctly during wiki entry fetch. * gn2/wqflask/templates/wiki/genewiki.html: Flash messages during errors. * gn2/wqflask/views.py (display_genewiki_page): Use "raise_for_status()" to handle errors. Signed-off-by: Munyoki Kilyungi --- gn2/wqflask/templates/wiki/genewiki.html | 1 + gn2/wqflask/views.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'gn2/wqflask') diff --git a/gn2/wqflask/templates/wiki/genewiki.html b/gn2/wqflask/templates/wiki/genewiki.html index 63f36741..496f5e28 100644 --- a/gn2/wqflask/templates/wiki/genewiki.html +++ b/gn2/wqflask/templates/wiki/genewiki.html @@ -1,6 +1,7 @@ {% extends "base.html" %} {% block title %}GeneWiki Entry for {{ symbol }}{% endblock %} {% block content %} + {{ flash_me() }}

GeneWiki Entries

diff --git a/gn2/wqflask/views.py b/gn2/wqflask/views.py index d40cfdb7..4e3c556d 100644 --- a/gn2/wqflask/views.py +++ b/gn2/wqflask/views.py @@ -1223,12 +1223,18 @@ def display_diffs_users(): @app.route("/genewiki/") def display_genewiki_page(symbol: str): """Fetch GeneRIF metadata from GN3 and display it""" - wiki = requests.get( - urljoin( - GN3_LOCAL_URL, - f"/api/metadata/wiki/{symbol}" + wiki = {} + try: + wiki = requests.get( + urljoin( + GN3_LOCAL_URL, + f"/api/metadata/wiki/{symbol}" + ) ) - ).json() + wiki.raise_for_status() + wiki = wiki.json() + except requests.RequestException as excp: + flash(excp, "alert-warning") return render_template( "wiki/genewiki.html", symbol=symbol, -- cgit v1.2.3