web/admin: improve error handling for non-rest_framework errors

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-06-01 23:34:16 +02:00
parent 9900cc5c81
commit f29344e91f

View file

@ -145,7 +145,10 @@ export class Form<T> extends LitElement {
})
);
return r;
}).catch((ex: Response) => {
}).catch((ex: Response | Error) => {
if (ex instanceof Error) {
throw ex;
}
if (ex.status > 399 && ex.status < 500) {
return ex.json().then((errorMessage: ValidationError) => {
if (!errorMessage) return errorMessage;
@ -169,6 +172,14 @@ export class Form<T> extends LitElement {
});
}
throw ex;
}).catch((ex: Error) => {
// error is local or not from rest_framework
showMessage({
message: ex.toString(),
level: MessageLevel.error,
});
// rethrow the error so the form doesn't close
throw ex;
});
}