run method

Future<CommandResult> run(
  1. Command command, {
  2. Map<String, String> headers = const {},
})

Send a command to the backend and get the results of running it, that is whether it was successful and validation errors if there were any.

Headers provided in headers are on top of the headers from the Cqrs constructor, meaning headers override _headers. Content-Type header will be ignored.

After successful completion returns CommandSuccess. A CommandFailure will be returned with an according CommandError in case of an error and with list of ValidationError errors (in case of validation error).

Implementation

Future<CommandResult> run(
  Command command, {
  Map<String, String> headers = const {},
}) async {
  final result = await _run(command, headers: headers);

  return _middlewares.fold(
    result,
    (result, middleware) async =>
        middleware.handleCommandResult(await result),
  );
}