nullOnError method
Future<T?>
nullOnError({
- FutureOr<
void> onError(- Object e,
- StackTrace s
- FutureOr<
void> onErrorOrNull(- Object? e,
- StackTrace? s
- AsyncExtensionErrorLogger? errorLogger,
- 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,
FutureOr<void> Function(Object? e, StackTrace? s)? onErrorOrNull,
AsyncExtensionErrorLogger? errorLogger,
bool logError = true}) async {
try {
var r = await this;
if (r == null && onErrorOrNull != null) {
await onErrorOrNull(null, null);
}
return r;
} catch (e, s) {
if (logError) errorLogger.logError(e, s);
if (onErrorOrNull != null) {
await onErrorOrNull(e, s);
} else if (onError != null) {
await onError(e, s);
}
return null;
}
}