diff --git a/src/main/resources/static/js/pages/list/list.js b/src/main/resources/static/js/pages/list/list.js index ec9e5e5..4d93617 100644 --- a/src/main/resources/static/js/pages/list/list.js +++ b/src/main/resources/static/js/pages/list/list.js @@ -1,3 +1,4 @@ +import { showError, initErrors } from "../../shared/error.js"; import * as api from "./api/listAPI.js" import * as ui from "./frontend/listUI.js" @@ -15,6 +16,7 @@ async function addItem(itemName, itemAmount, categoryID) { if (!response.ok) { console.error(`Error, item couldnt be created ${json}`); + showError(json.msg); return; } @@ -29,7 +31,9 @@ async function addCategory(categoryName) { const json = await response.json(); if (!response.ok) { - console.error(`Error, category couldnt be created ${json}`) + console.error(`Error, category couldnt be created ${json}`); + showError(json.msg); + return; } @@ -59,6 +63,7 @@ async function editItem(textElement) { if (!response.ok) { const json = await response.json(); console.error(`Error editingItem ${json}`); + showError(json.msg) return; } @@ -99,6 +104,7 @@ function editCategory(categoryElement) { if (!response.ok) { const json = await response.json(); console.error(`Error editing category ${json}`); + showError(json.msg); return; } @@ -121,6 +127,7 @@ async function deleteItem(li) { if (!response.ok) { const json = await response.json(); console.error(`Error deleting item ${json}`); + showError(json.msg); return; } @@ -134,6 +141,7 @@ async function deleteCategory(deleteAllItems, categoryID) { if (!response.ok) { const json = await response.json(); console.error(`Error deleting category ${json}`); + showError(json.msg); return; } ui.deleteCategory(deleteAllItems, categoryID); @@ -146,12 +154,17 @@ async function deleteAllDoneItems() { if (!response.ok) { const json = await response.json(); console.error(`Error deleting all done items ${json}`); + showError(json.msg); + return; } ui.deleteAllDoneItems(); } function init() { + + initErrors(document.querySelector(".nav")); + addCategoryForm.addEventListener("submit", (event) => { event.preventDefault(); let formData = Object.fromEntries(new FormData(addCategoryForm));