onFailureOf method
Runs callback if this is a failure and its outcomes intersect with matchOutcomes.
matchOutcomes accepts a single String or a List<String>:
httpResult
.onFailureOf('unauthorized', (_) => redirectToLogin())
.onFailureOf(['badGateway', 'internalServerError'], (_) => showRetryBanner())
.onFailure((outcome, _) => logger.error('Unhandled: $outcome'));
Non-matching failures pass through unchanged; successes are always ignored. For a catch-all failure handler, use onFailure.
Implementation
Result<Value> onFailureOf(Object? matchOutcomes, void Function(Object? context) callback) {
final targets = _toOutcomes(matchOutcomes);
if (this case Failure(:final context) when outcomes.any(targets.contains)) callback(context);
return this;
}