@alanscodelog/utils
    Preparing search index...

    Function returnIfError

    • 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.

      const maybeError = returnError<KnownPossibleError>(funcThatMaybeThrows)
      

      Type Parameters

      Parameters

      • func: T

      Returns T extends AnyFunction ? ReturnType<T<T>> : TError | T