Skip to content
Snippets Groups Projects
Commit 2f0a4d62 authored by Max Lou's avatar Max Lou
Browse files

Tweaking getResult error handling

parent ada1a4db
Branches
No related tags found
No related merge requests found
......@@ -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,
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment