If you await on this function above, you will have to wrap it inside of a try / catch statement to prevent a runtime error. Further, there's no way you could encode the potential for failure into the above function. It's identical in behaviour to using throw ... So you lose all type safety.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hey Julian,
Glad you enjoyed the article!
Well, using
Promise.reject
inside anasync
function is just an alternative to usingthrow
.Consider this example:
If you
await
on this function above, you will have to wrap it inside of atry / catch
statement to prevent a runtime error. Further, there's no way you could encode the potential for failure into the above function. It's identical in behaviour to usingthrow
... So you lose all type safety.