From 2a75863e843dbe48f411f13a6869c5f25baa1aa0 Mon Sep 17 00:00:00 2001 From: Phill Pover Date: Mon, 7 Apr 2025 11:24:55 +0100 Subject: [PATCH] Pushing errors back to frontend --- frontend/src/app/album/page.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/album/page.tsx b/frontend/src/app/album/page.tsx index a0d15cf..4883cf7 100644 --- a/frontend/src/app/album/page.tsx +++ b/frontend/src/app/album/page.tsx @@ -47,12 +47,22 @@ export default function Page() { try { if (formData.get('id') == "") { const result = createAlbum(formData) - .then(response => {return response.json()}) + .then(response => { + if (response.ok) { + return response.json() + } + Promise.reject(response); + }) .catch(error => {return error.json()}); handleSnackbar(`Successfully updated Album with ID ${formData.get("id")}: ${result}`, true); } else { const result = updateAlbum(formData) - .then(response => {return response.json()}) + .then(response => { + if (response.ok) { + return response.json() + } + Promise.reject(response); + }) .catch(error => {return error.json()}); handleSnackbar(`Successfully updated Album with ID ${formData.get("id")}: ${result}`, true); }