diff --git a/src/components/factory.ts b/src/components/factory.ts index 6402027..ab16629 100644 --- a/src/components/factory.ts +++ b/src/components/factory.ts @@ -31,7 +31,11 @@ export const notify = (body: string|any, notifyType:string ='info', other?: any) type asyncFunction = (...args:any) => Promise; -export const invokeWebApiWrapperAsync = async (funcAsync: asyncFunction, setShowLoader: Dispatch>, errorNotifyText: string) => { +export const invokeWebApiWrapperAsync = async ( + funcAsync: asyncFunction, + setShowLoader: Dispatch>, + errorNotifyText: (string | ((ex: unknown) => string)) +) => { if(setShowLoader) setShowLoader(true) try{ @@ -39,8 +43,11 @@ export const invokeWebApiWrapperAsync = async (funcAsync: asyncFunction, setShow } catch (ex) { if(process.env.NODE_ENV === 'development') console.error(ex) - if(errorNotifyText) - notify(errorNotifyText, 'error') + if(errorNotifyText) { + if (typeof errorNotifyText === 'function') + notify(errorNotifyText(ex), 'error') + else notify(errorNotifyText, 'error') + } } finally{ if(setShowLoader) setShowLoader(false)