deltachat / deltachat-desktop

Email-based instant messaging for Desktop.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

helper function for user visible errors on exception in async action

Simon-Laux opened this issue · comments

we should make a helper function for this:

Some hook like

function useCallbackWithUserAlert(cb, dependencies, alertMessage) {
 const openAlertDialog = useAlertDialog()
 return useCallback(()=>{
  return async (...args) => {
  try {
    await cb(...args)
  } catch (error) {
    log.error(alertMessage, error)
    openAlertDialog({
      message: alertMessage + error && error.message ?? error.toString()
    })
  }
 }, [openAlertDialog,...dependencies])
}

that we could use in these places:

const startChatWithContact = useCallbackWithUserAlert(async (addr: string) => {}, [])

Originally posted by @Simon-Laux in #3840 (comment)