tryCatch method

Future<Validation<T>> tryCatch()

Implementation

Future<Validation<T>> tryCatch() =>
    then((value) => Valid<T>(value)).catchError((err) {
      if (err is Exception) {
        return Invalid<T>([Fail.withException(err)]);
      } else if (err is Error) {
        return Invalid<T>([Fail.withError(err)]);
      }
      else if(err is String)
      {
        return Invalid<T>([Fail.withError(ArgumentError(err))]);
      }

      return Fail.withError(Error(), message: 'Unknown error').toInvalid<T>();
    });