From 94e3fe49b36f07b0cd4f12f3ac730fb3c9a3b366 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Mon, 21 Oct 2024 15:18:43 +0300 Subject: [PATCH] add error handling on the response from the client side --- script.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index ed01cf8..6460c52 100644 --- a/script.js +++ b/script.js @@ -41,7 +41,12 @@ const form = document.getElementById('merge-form'); }, body: JSON.stringify({ calendars: calendarsData }) }) - .then((response) => response.json()) + .then((response) => { + if (!response.ok) { + return response.json().then(err => { throw err; }); + } + return response.json(); + }) .then((data) => { result.innerHTML = `Merged calendar URL: ${data.url}`; console.log('Links added successfully!');