add error handling on the response from the client side

This commit is contained in:
Ryan Mwangi 2024-10-21 15:18:43 +03:00
parent 6c3fa294d6
commit 94e3fe49b3
1 changed files with 6 additions and 1 deletions

View File

@ -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: <a href="${data.url}">${data.url}</a>`;
console.log('Links added successfully!');