From 2c04a4ad00dbb228360da5575c19571a151c11a1 Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Mon, 28 Nov 2022 14:45:57 +0300 Subject: Fail gracefully when virtuoso is not accessible * gn3/api/metadata.py: import RemoteDisconnected. (jsonify_dataset_metadata): Wrap get_dataset_metadata in try block. --- gn3/api/metadata.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'gn3') 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/", 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({}) + -- cgit v1.2.3