Docs / ArchitectureKit / Fundamentals / Handling Errors
Handling Errors
Every error ArchitectureKit returns belongs to one of four categories. Use errors.Is to check for a category rather than for a concrete error:
ErrDomainmeans that a business rule rejected the command, as withNewDomainError.ErrConflictmeans that a precondition did not hold.ErrTransientmeans that trying again may help, for example if reading from the database failed.ErrPermanentmeans that trying again will not help, for example if an event could not be decoded, or if a subject contains an event type the state has noEvolverule for.
writtenEvents, err := architecturekit.Execute(
// ...
)
switch {
case errors.Is(err, architecturekit.ErrDomain):
// A business rule rejected the command.
case errors.Is(err, architecturekit.ErrConflict):
// A precondition did not hold.
case errors.Is(err, architecturekit.ErrTransient):
// Trying again may help.
case errors.Is(err, architecturekit.ErrPermanent):
// Trying again will not help.
}
Note that ErrConflict is a special case of ErrTransient, so check for it first.
Note that Execute does not retry. To try again, for example after a conflict, call Execute again.