Returns the error of the given function if it throws, otherwise returns the result. Also works with promises (works like a .catch(e => e)).
.catch(e => e)
Note that it's impossible to type this properly, you can change the return type of the error using the first type param.
const maybeError = returnError<KnownPossibleError>(funcThatMaybeThrows) Copy
const maybeError = returnError<KnownPossibleError>(funcThatMaybeThrows)
Returns the error of the given function if it throws, otherwise returns the result. Also works with promises (works like a
.catch(e => e)
).Note that it's impossible to type this properly, you can change the return type of the error using the first type param.