Skip to content

Instantly share code, notes, and snippets.

@LucasFsc
Created August 12, 2020 17:39
Show Gist options
  • Save LucasFsc/06d5c004afeefed618095965599b1936 to your computer and use it in GitHub Desktop.
Save LucasFsc/06d5c004afeefed618095965599b1936 to your computer and use it in GitHub Desktop.
Promise async try catch util
export default async ({
promise,
onResponse = () => {},
onLoad = () => {},
onError = () => {},
onComplete = () => {}
}) => {
onLoad(true)
try {
onResponse(await promise)
} catch (error) {
onError(error)
} finally {
onLoad(false)
onComplete()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment