guardStream<R> method
Protects the provided function from throwing an unhandled exception
The left side of the returned Either
will be a FirestoreFailure if any
errors are triggered by the streamCallback
Implementation
Stream<Either<Failure, R>> guardStream<R>(
Stream<R> Function() streamCallback,
) async* {
try {
await for (final result in streamCallback()) {
yield Right(result);
}
} catch (e, stack) {
if (e is FormatException) {
// ignore: avoid_print
print('Format Exception: ${e.message}');
}
yield Left(
FirestoreFailure(
error: e,
stackTrace: Chain.forTrace(stack),
),
);
}
}