diff --git a/src/js/utils.js b/src/js/utils.js index 4524cf4ded943dadb024cbf7ea8c4ea2932ead50..459a474615989bca985094921f915dd0949fb783 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -8,16 +8,14 @@ import { GridStack } from "gridstack"; * @returns */ export async function getResult(token, url) { - try { - const response = await fetch(url, { - headers: { - Authorization: `Basic ${token}`, - }, - }); - return await response.json(); - } catch (error) { - throw Error("Fetching result from backend failed. Please check URL and TOKEN settings."); - } + const response = await fetch(url, { + headers: { + Authorization: `Basic ${token}`, + }, + }); + const data = await response.json(); + if (response.status !== 200) throw Error(data.message); + return data; } /** @@ -110,7 +108,7 @@ function removeAllChildNodes(parent) { * @param {*} items */ export function initGrid(initialWidgets, items) { - let widgets = initialWidgets + let widgets = initialWidgets; // Basic grid object const grid = GridStack.init({ cellHeight: 70, @@ -273,10 +271,10 @@ export function initGrid(initialWidgets, items) { /** * Refresh widgets with updated widgets array. - * @param {*} newWidgets + * @param {*} newWidgets */ function refreshWidgets(newWidgets) { - widgets = newWidgets + widgets = newWidgets; plotWidgets(grid.engine.nodes, widgets); } @@ -287,6 +285,6 @@ export function initGrid(initialWidgets, items) { load, enableWidgetMoveAndResize, disableWidgetMoveAndResize, - refreshWidgets + refreshWidgets, }; }