From 3f4464b068fcc3ef75e20b202e206e44828b1bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Wed, 18 Aug 2021 10:35:05 +0500 Subject: [PATCH] Add sync method invokeWebApiWrapper --- src/components/factory.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/components/factory.ts b/src/components/factory.ts index dca00cf..3dd5ec6 100644 --- a/src/components/factory.ts +++ b/src/components/factory.ts @@ -69,6 +69,22 @@ export const makePaginationObject = (paginationContainer:PaginationContainer, .. } } +export const invokeWebApiWrapper = async (func: Function, setShowLoader: Dispatch>, errorNotifyText: string) => { + if(setShowLoader) + setShowLoader(true) + try{ + func() + } catch (ex) { + if(process.env.NODE_ENV === 'development') + console.log(ex) + if(errorNotifyText) + notify(errorNotifyText, 'error') + } finally{ + if(setShowLoader) + setShowLoader(false) + } +} + export const invokeWebApiWrapperAsync = async (funcAsync: asyncFunction, setShowLoader: Dispatch>, errorNotifyText: string) => { if(setShowLoader) setShowLoader(true)