mapErr method

AsyncSnapshot<T> mapErr(
  1. Object fn(
    1. Object
    )
)

Transforms the snapshot by applying a function to the Error value.

fn - The function to apply to the Error value. Returns a new AsyncSnapshot with the transformed error. If the snapshot isn't an Error, it gets passed through.

Example:

err<int>(Exception('test')).mapErr((e) => Exception('Wrapped: $e'));
ok(42).mapErr((e) => e); // ok(42) - passes through

Implementation

AsyncSnapshot<T> mapErr(Object Function(Object) fn) {
  if (isOk()) return ok<T>(data as T);
  if (isPending()) return pending<T>();

  return err<T>(fn(error!), stackTrace);
}