fix error handling
This commit is contained in:
1 parent
a18ccb635d
commit
23a9c9b97a
1 file changed
+7
-21
@@ -123,31 +123,17 @@ const Settings = () => {
|
|||||||
ttl: form.ttl,
|
ttl: form.ttl,
|
||||||
});
|
});
|
||||||
const updatedUser = { ...user, checkTTL: form.ttl };
|
const updatedUser = { ...user, checkTTL: form.ttl };
|
||||||
const action = await dispatch(update({ localData: updatedUser }));
|
const [userAction, settingsAction] = await Promise.all([
|
||||||
const settingsAction = await dispatch(
|
dispatch(update({ localData: updatedUser })),
|
||||||
updateAppSettings({ settings: { language: language } })
|
dispatch(updateAppSettings({ settings: { language: language } })),
|
||||||
);
|
]);
|
||||||
|
|
||||||
if (action.payload.success && settingsAction.payload.success) {
|
if (userAction.payload.success && settingsAction.payload.success) {
|
||||||
createToast({
|
createToast({ body: t("settingsSuccessSaved") });
|
||||||
body: t("settingsSuccessSaved"),
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
if (action.payload) {
|
throw new Error("Failed to save settings");
|
||||||
console.log(action.payload);
|
|
||||||
// dispatch errors
|
|
||||||
createToast({
|
|
||||||
body: action.payload.msg,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// unknown errors
|
|
||||||
createToast({
|
|
||||||
body: "Unknown error.",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
createToast({ body: t("settingsFailedToSave") });
|
createToast({ body: t("settingsFailedToSave") });
|
||||||
} finally {
|
} finally {
|
||||||
setChecksIsLoading(false);
|
setChecksIsLoading(false);
|
||||||
|
|||||||
Reference in new issue
Block a user