From 74b00258bdd1936a934770590eeb46b3da9e2fe3 Mon Sep 17 00:00:00 2001 From: D13ce Date: Mon, 23 Oct 2023 11:18:09 +0200 Subject: [PATCH 1/2] (BIDS-2591) Improve return value for dashboard effectiveness --- handlers/dashboard.go | 2 +- static/js/dashboard.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/handlers/dashboard.go b/handlers/dashboard.go index c1839fb05d..217c442b74 100644 --- a/handlers/dashboard.go +++ b/handlers/dashboard.go @@ -988,7 +988,7 @@ func DashboardDataEffectiveness(w http.ResponseWriter, r *http.Request) { } if len(activeValidators) == 0 { - http.Error(w, "Invalid query", http.StatusBadRequest) + w.WriteHeader(http.StatusNoContent) return } diff --git a/static/js/dashboard.js b/static/js/dashboard.js index 4e6a4ed208..f3dcfbe96f 100644 --- a/static/js/dashboard.js +++ b/static/js/dashboard.js @@ -975,6 +975,7 @@ $(document).ready(function () { fetch(`/dashboard/data/effectiveness${getValidatorQueryString()}`, { method: "GET", }).then((res) => { + if (res.status !== 200) return res.json().then((data) => { let sum = 0.0 for (let eff of data) { From 273fd46cf8f243c6086077e75c8c2e9aac0ddf33 Mon Sep 17 00:00:00 2001 From: D13ce Date: Tue, 24 Oct 2023 08:59:05 +0200 Subject: [PATCH 2/2] (BIDS-2591) Changes based on code review --- handlers/dashboard.go | 3 ++- static/js/dashboard.js | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/handlers/dashboard.go b/handlers/dashboard.go index 217c442b74..ece52d5eea 100644 --- a/handlers/dashboard.go +++ b/handlers/dashboard.go @@ -988,7 +988,8 @@ func DashboardDataEffectiveness(w http.ResponseWriter, r *http.Request) { } if len(activeValidators) == 0 { - w.WriteHeader(http.StatusNoContent) + // valid 200 response with empty data + w.Write([]byte(`{}`)) return } diff --git a/static/js/dashboard.js b/static/js/dashboard.js index f3dcfbe96f..b22eb2e135 100644 --- a/static/js/dashboard.js +++ b/static/js/dashboard.js @@ -975,8 +975,10 @@ $(document).ready(function () { fetch(`/dashboard/data/effectiveness${getValidatorQueryString()}`, { method: "GET", }).then((res) => { - if (res.status !== 200) return res.json().then((data) => { + if (Object.keys(data).length === 0) { + return + } let sum = 0.0 for (let eff of data) { sum += eff