aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2022-11-28 14:45:57 +0300
committerBonfaceKilz2022-11-28 15:22:11 +0300
commit2c04a4ad00dbb228360da5575c19571a151c11a1 (patch)
treed598506af568e92d0e9dd0dae63483c0d99085d8
parent9810731b8432624c3817633ea0877dd80d0eea39 (diff)
downloadgenenetwork3-2c04a4ad00dbb228360da5575c19571a151c11a1.tar.gz
Fail gracefully when virtuoso is not accessible
* gn3/api/metadata.py: import RemoteDisconnected. (jsonify_dataset_metadata): Wrap get_dataset_metadata in try block.
-rw-r--r--gn3/api/metadata.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/gn3/api/metadata.py b/gn3/api/metadata.py
index 4fe9e67..680d51b 100644
--- a/gn3/api/metadata.py
+++ b/gn3/api/metadata.py
@@ -1,4 +1,5 @@
"""API for fetching metadata using an API"""
+from http.client import RemoteDisconnected
from flask import Blueprint
from flask import jsonify
from flask import current_app
@@ -14,9 +15,14 @@ metadata = Blueprint("metadata", __name__)
@metadata.route("/dataset/<accession_id>", methods=["GET"])
def jsonify_dataset_metadata(accession_id):
"""Fetch a dataset's metadata given it's ACCESSION_ID"""
- return jsonify(get_dataset_metadata(
- SPARQLWrapper(current_app
- .config
- .get("SPARQL_ENDPOINT")),
- accession_id
- ).data)
+ try:
+ return jsonify(
+ get_dataset_metadata(
+ SPARQLWrapper(current_app.config.get("SPARQL_ENDPOINT")),
+ accession_id,
+ ).data
+ )
+ # The virtuoso server is misconfigured or it isn't running at all
+ except RemoteDisconnected:
+ return jsonify({})
+