From ea01716ed665b58c64fffd806ee0f6baf1448793 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Tue, 8 Mar 2022 10:23:43 -0800 Subject: [PATCH] Fix NPE error --- packages/webapp/src/redux/clientSlice.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/webapp/src/redux/clientSlice.ts b/packages/webapp/src/redux/clientSlice.ts index 1fe4f199..40e45fb8 100644 --- a/packages/webapp/src/redux/clientSlice.ts +++ b/packages/webapp/src/redux/clientSlice.ts @@ -47,12 +47,15 @@ export const fetchMapById = (id: number): MapLoadResult => { return client.fetchAllMaps(); }); - // Sanitize error structure ... - let errorMsg: ErrorInfo = Object.keys(error).length !== 0 ? error : null; - // If the map can not be loaded, create an error object. let map: MapInfo; + let errorMsg: ErrorInfo; if (!isLoading) { + // Sanitize error structure ... + if (error) { + errorMsg = Object.keys(error).length !== 0 ? error : null; + } + // Seach for 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` }