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 => {
dispatch(authenticate(user));
})
.catch((error: Error) => {
.catch((error: unknown) => {
console.error(error);
if (error instanceof Error) {
dispatch(
addSnackbar({
type: 'warning',
message: {
key: 'ui.toast.onFailToAuth',
message: error.message,
options: {
details: error.message,
},
},
}),
);
dispatch(authError(error));
}
});
};
}

View File

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

View File

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

View File

@ -55,7 +55,10 @@ export function checkBackendStatus() {
dispatch(
addSnackbar({
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) {
alert({
title: 'auth.errors.authTitle',
body: { key: 'auth.errors.authBody', options: { details: err } },
body: { key: 'auth.errors.authBody', options: { details: err.toString() } },
});
return;
} else if (data) {

View File

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