Handle request errors

This commit is contained in:
Brain 2022-08-24 15:15:08 +02:00
parent f9229b5998
commit 0882053a42
Signed by untrusted user: Brain
GPG Key ID: 9CF47083EE57670D
1 changed files with 10 additions and 1 deletions

View File

@ -16,10 +16,19 @@ window.addEventListener('DOMContentLoaded', function(event) {
mode: 'same-origin', mode: 'same-origin',
body: formData, body: formData,
}) })
.then(response => response.json()) .then(response => {
if (!response.ok) {
throw new Error('Response was not OK');
}
return response.json();
})
.then(json => { .then(json => {
console.log(json); console.log(json);
}) })
.catch(error => {
console.error('Could not start the session:', error);
});
}); });
contact_form.addEventListener('submit', function(event) { contact_form.addEventListener('submit', function(event) {