Created
January 15, 2024 19:23
-
-
Save jswhisperer/dd917a3bce99f9468e42ad4db09511d3 to your computer and use it in GitHub Desktop.
await without catch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const doAwait = async (promise) => { | |
try { | |
const data = await promise; | |
return [undefined, data]; | |
} catch (error) { | |
return [error, undefined]; | |
} | |
}; | |
const [error, result] = await doAwait(myPromise); | |
if (error) { | |
throw error; | |
} | |
doStuff(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment