failure method

Failure<Value> failure(
  1. Object? outcomes, [
  2. Object? context
])

Signals that the service could not complete its work.

outcomes accepts a single String or a List<String>. The optional context carries whatever the caller needs to act on the failure:

// carry the invalid entity so the caller can render field errors
return failure('validationFailed', invalidUser);

// multiple outcomes with context
return failure(['unprocessableContent', 'clientError'], response);

// outcome tag alone is enough
return failure('unauthorized');

See also success for the happy path, check for inline validation, tryRun for wrapping operations that may throw.

Implementation

Failure<Value> failure(Object? outcomes, [Object? context]) => Failure(outcomes, context);