guard<ValueT> static method
Transforms exceptions into Failure.other.
This is useful when
- expected error type is Failure.
- you don't need to handle specific error cases.
Implementation
static Future<Result<ValueT, Failure>> guard<ValueT>(
Future<ValueT> Function() run,
) async {
try {
return Result.success(await run());
} on Failure catch (e) {
return Result.failure(e);
} catch (e) {
return const Result.failure(
Failure.other,
);
}
}