From f48662bb6ef9445acc8ab4f6e91bfdc63a6c34a6 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Tue, 8 Mar 2022 10:05:24 -0800 Subject: [PATCH] Improve error handling --- packages/webapp/src/redux/clientSlice.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/webapp/src/redux/clientSlice.ts b/packages/webapp/src/redux/clientSlice.ts index ef7329df..6cc61b22 100644 --- a/packages/webapp/src/redux/clientSlice.ts +++ b/packages/webapp/src/redux/clientSlice.ts @@ -47,9 +47,18 @@ export const fetchMapById = (id: number): MapLoadResult => { return client.fetchAllMaps(); }); - const result = data?.find((m) => m.id == id); - const map = result || null; - return { isLoading: isLoading, error: error, map: map }; + let errorMsg: ErrorInfo = Object.keys(error).length !== 0 ? error : null; + let map: MapInfo; + if (!isLoading) { + // Sanitize error structure ... + + // If the map can not be loaded, create an error object. + map = data?.find((m) => m.id == id); + if (map === null && !errorMsg) { + errorMsg = { msg: `Map with id ${id} could not be found. Please, reflesh the page` } + } + } + return { isLoading: isLoading, error: errorMsg, map: map }; }; export const fetchAccount = (): AccountInfo | undefined => {