Fix snackbar errors

This commit is contained in:
Daniel Lautzenheiser 2022-10-26 11:46:44 -04:00
parent 03815ec2f0
commit e36698aa9a
6 changed files with 47 additions and 23 deletions

View File

@ -86,18 +86,22 @@ export function loginUser(credentials: Credentials) {
.then(user => { .then(user => {
dispatch(authenticate(user)); dispatch(authenticate(user));
}) })
.catch((error: Error) => { .catch((error: unknown) => {
console.error(error); console.error(error);
if (error instanceof Error) {
dispatch( dispatch(
addSnackbar({ addSnackbar({
type: 'warning', type: 'warning',
message: { message: {
key: 'ui.toast.onFailToAuth', key: 'ui.toast.onFailToAuth',
message: error.message, options: {
details: error.message,
},
}, },
}), }),
); );
dispatch(authError(error)); dispatch(authError(error));
}
}); });
}; };
} }

View File

@ -624,8 +624,10 @@ export function loadEntry(collection: Collection, slug: string, silent = false)
type: 'error', type: 'error',
message: { message: {
key: 'ui.toast.onFailToLoadEntries', key: 'ui.toast.onFailToLoadEntries',
options: {
details: error.message, details: error.message,
}, },
},
}), }),
); );
dispatch(entryLoadError(error, collection, slug)); dispatch(entryLoadError(error, collection, slug));
@ -744,8 +746,10 @@ export function loadEntries(collection: Collection, page = 0) {
type: 'error', type: 'error',
message: { message: {
key: 'ui.toast.onFailToLoadEntries', key: 'ui.toast.onFailToLoadEntries',
options: {
details: error.message, details: error.message,
}, },
},
}), }),
); );
return Promise.reject(dispatch(entriesFailed(collection, error))); return Promise.reject(dispatch(entriesFailed(collection, error)));
@ -803,8 +807,10 @@ export function traverseCollectionCursor(collection: Collection, action: string)
type: 'error', type: 'error',
message: { message: {
key: 'ui.toast.onFailToLoadEntries', key: 'ui.toast.onFailToLoadEntries',
options: {
details: error.message, details: error.message,
}, },
},
}), }),
); );
return Promise.reject(dispatch(entriesFailed(collection, error))); return Promise.reject(dispatch(entriesFailed(collection, error)));
@ -1071,8 +1077,10 @@ export function persistEntry(collection: Collection) {
type: 'error', type: 'error',
message: { message: {
key: 'ui.toast.onFailToPersist', key: 'ui.toast.onFailToPersist',
options: {
details: error, details: error,
}, },
},
}), }),
); );
return Promise.reject(dispatch(entryPersistFail(collection, serializedEntry, error))); return Promise.reject(dispatch(entryPersistFail(collection, serializedEntry, error)));
@ -1102,8 +1110,10 @@ export function deleteEntry(collection: Collection, slug: string) {
type: 'error', type: 'error',
message: { message: {
key: 'ui.toast.onFailToDelete', key: 'ui.toast.onFailToDelete',
options: {
details: error, details: error,
}, },
},
}), }),
); );
console.error(error); console.error(error);

View File

@ -337,8 +337,10 @@ export function persistMedia(file: File, opts: MediaOptions = {}) {
type: 'error', type: 'error',
message: { message: {
key: 'ui.toast.onFailToPersistMedia', key: 'ui.toast.onFailToPersistMedia',
options: {
details: error, details: error,
}, },
},
}), }),
); );
return dispatch(mediaPersistFailed({ privateUpload })); return dispatch(mediaPersistFailed({ privateUpload }));
@ -381,8 +383,10 @@ export function deleteMedia(file: MediaFile, opts: MediaOptions = {}) {
type: 'error', type: 'error',
message: { message: {
key: 'ui.toast.onFailToDeleteMedia', key: 'ui.toast.onFailToDeleteMedia',
options: {
details: error.message, details: error.message,
}, },
},
}), }),
); );
} }
@ -417,8 +421,10 @@ export function deleteMedia(file: MediaFile, opts: MediaOptions = {}) {
type: 'error', type: 'error',
message: { message: {
key: 'ui.toast.onFailToDeleteMedia', key: 'ui.toast.onFailToDeleteMedia',
options: {
details: error.message, details: error.message,
}, },
},
}), }),
); );
} }

View File

@ -55,7 +55,10 @@ export function checkBackendStatus() {
dispatch( dispatch(
addSnackbar({ addSnackbar({
type: 'error', type: 'error',
message: { key: 'ui.toast.onBackendDown', details: status.api.statusPage }, message: {
key: 'ui.toast.onBackendDown',
options: { details: status.api.statusPage },
},
}), }),
); );
} }

View File

@ -34,7 +34,7 @@ const AzureAuthenticationPage = ({
if (err) { if (err) {
alert({ alert({
title: 'auth.errors.authTitle', title: 'auth.errors.authTitle',
body: { key: 'auth.errors.authBody', options: { details: err } }, body: { key: 'auth.errors.authBody', options: { details: err.toString() } },
}); });
return; return;
} else if (data) { } else if (data) {

View File

@ -11,9 +11,10 @@ export interface SnackbarMessage {
type: MessageType; type: MessageType;
message: message:
| string | string
| ({ | {
key: string; key: string;
} & Record<string, unknown>); options?: Record<string, unknown>;
};
} }
// Define a type for the slice state // Define a type for the slice state