Catch error responses from API

This commit is contained in:
Mouse Reeve 2021-09-10 08:59:49 -07:00
parent 3a7717e22f
commit e3ab5afcbd

View file

@ -74,11 +74,16 @@ let StatusCache = new class {
BookWyrm.addRemoveClass(form, 'is-processing', false); BookWyrm.addRemoveClass(form, 'is-processing', false);
trigger.removeAttribute('disabled'); trigger.removeAttribute('disabled');
}) })
.then(this.submitStatusSuccess.bind(this, form)) .then(response => {
if (!response.ok) {
throw new Error();
}
this.submitStatusSuccess(form);
})
.catch(error => { .catch(error => {
// @todo Display a notification in the UI instead. // @todo Display a notification in the UI instead.
// For now, the absence of change will be enough. // For now, the absence of change will be enough.
console.warn('Request failed:', error); console.log('Request failed:', error);
BookWyrm.addRemoveClass(form, 'has-error', form.className.indexOf('is-hidden') == -1); BookWyrm.addRemoveClass(form, 'has-error', form.className.indexOf('is-hidden') == -1);
}); });