From 40ed036abc48e8c20f14d12e423fea6ce44e1139 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Sat, 20 Mar 2021 15:06:10 +0300 Subject: [PATCH] [RNBS-021] - better error messages structure --- src/map.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/map.ts b/src/map.ts index e972c27..1592b4f 100644 --- a/src/map.ts +++ b/src/map.ts @@ -6,6 +6,7 @@ const cache = {} as any; export const isCached = (componentName: string) => !!cache[componentName]; const DEPRECATED_API_MESSAGE = "You are using a deprecated API that will be removed in a future releases. Please consider using `loader` instead of `require`"; +const ERROR_WHILE_LOADING = "An error occurred while lazy loading a component. Perhaps the path where you are trying to load the component does not exist? Stacktrace: "; // In react-native world call of `require` or `loader` will block thread (since it's sync operation) // As a result if screen is not loaded yet and you trigger a navigation - app will freeze for a time, @@ -17,8 +18,10 @@ const nonBlockingLoader = (loader: RequireLoader | ImportLoader) => new Promise( const file = await loader(); resolve(file); } catch (e) { - console.error("An error occurred while lazy loading a component. Perhaps the path where you are trying to load the component does not exist? Stacktrace: " + e); - resolve(null); // resolve it as a `null` - another error will be thrown when it will evaluate `component[rest.extract]` + console.error(ERROR_WHILE_LOADING + e); + // resolve it as a `null` - another error will be thrown + // when it will evaluate `component[rest.extract]` + resolve(null); } }, 0); });