Add sync method invokeWebApiWrapper

This commit is contained in:
Фролов 2021-08-18 10:35:05 +05:00
parent 178057049f
commit 3f4464b068

View File

@ -69,6 +69,22 @@ export const makePaginationObject = (paginationContainer:PaginationContainer, ..
}
}
export const invokeWebApiWrapper = async (func: Function, setShowLoader: Dispatch<SetStateAction<boolean>>, 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<SetStateAction<boolean>>, errorNotifyText: string) => {
if(setShowLoader)
setShowLoader(true)