onCommandFailure method
Send error response when command processing fails
Implementation
@override
Future<void> onCommandFailure(Command command, dynamic error) async {
await super.onCommandFailure(command, error);
if (!_isInActorSystem()) return;
// Removed on first use: eventador calls onCommandFailure twice for one
// failed command (AggregateRoot and PersistentActor), and the caller
// got every failure reply twice.
final sender = _capturedSenders.remove(command.commandId);
if (sender == null) return;
final invoiceId = command is InvoiceCommand ? command.invoiceId : aggregateId;
// A refusal, and the invoice's status as it stands: it used to say
// "pending" and succeeded, whatever the invoice was, so a refused
// payment of a paid invoice read as a pending invoice (bead
// libspiffy-mu09).
sender.tell(InvoiceStatusMessage(
invoiceId: invoiceId,
status: state?.status ?? InvoiceStatus.pending,
statusMessage: 'Command failed: $error',
success: false,
error: '$error',
));
}