nullOnError method

Future<T?> nullOnError({
  1. FutureOr<void> onError(
    1. Object e,
    2. StackTrace s
    )?,
  2. AsyncExtensionErrorLogger? errorLogger,
  3. bool logError = true,
})

Returns this Future value or null if it throws an error.

Logs the error using errorLogger or defaultAsyncExtensionErrorLogger if parameter logError is true.

Implementation

Future<T?> nullOnError(
    {FutureOr<void> Function(Object e, StackTrace s)? onError,
    AsyncExtensionErrorLogger? errorLogger,
    bool logError = true}) async {
  try {
    var r = await this;
    return r;
  } catch (e, s) {
    if (logError) errorLogger.logError(e, s);
    if (onError != null) {
      await onError(e, s);
    }
    return null;
  }
}