From aae83fe04ad3de1ed4558f863f9be86cf0345cd0 Mon Sep 17 00:00:00 2001 From: Matthieu Barba Date: Sat, 2 Mar 2024 19:10:17 +0000 Subject: [PATCH] Properly show message if failure --- js/index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/js/index.js b/js/index.js index 7c7b8ad..81a1694 100755 --- a/js/index.js +++ b/js/index.js @@ -1,3 +1,5 @@ +//import { check_data_error } from "./utils.js"; + function print_db() { pars = {}; pars.type = 'databases'; @@ -5,12 +7,26 @@ function print_db() { console.log(str); console.log(format_url(urls.get_data, pars)); $.getJSON( urls.get_data, pars, function(data) { + error_msg = check_data_error(data); + if (error_msg) { + $( "#databases" ).append( error_msg ); + } else { print_db_table(data); + } }).fail(function(){ console.log("Failed databases retrieval"); }); } +function check_data_error( data ) { + error_msg = "" + if ("outcome" in data && data["outcome"] == false) { + console.log("Error occurred: " + data["details"]); + error_msg = $("

").text("An error occurred: " + data["message"] + ". Check the console for more details."); + } + return error_msg; +} + function get_dbs() { var dbs = {};