@jenova-marie/ts-rust-result - v2.2.12
    Preparing search index...

    Function mapErr

    • Maps an error Result using the provided function. If the Result is successful, returns the success unchanged.

      Type Parameters

      • T

        The type of the successful value

      • E = Error

        The type of the input error

      • F = Error

        The type of the output error

      Parameters

      • result: Result<T, E>

        The Result to map the error of

      • fn: (err: E) => F

        Function to transform the error

      Returns Result<T, F>

      A new Result with the transformed error, or the original success

      const errorResult = err(new Error("Network error"))
      const enhancedError = mapErr(errorResult, err =>
      new Error(`API call failed: ${err.message}`)
      ) // err(Error("API call failed: Network error"))