Files
sxchnge/backend/pkg/merrors/ledger.go
T

66 lines
1.8 KiB
Go

package merrors
import "strings"
const (
ReasonLedgerIdempotencyConflict = "LEDGER_IDEMPOTENCY_CONFLICT"
ReasonLedgerCommandIdentityMismatch = "LEDGER_COMMAND_IDENTITY_MISMATCH"
ReasonLedgerAccessViolation = "LEDGER_ACCESS_VIOLATION"
ReasonAccountNotEligible = "ACCOUNT_NOT_ELIGIBLE"
)
var ErrLedgerIdempotencyConflict = Define("ledger.idempotency_conflict")
var ErrLedgerCommandIdentityMismatch = Define("ledger.command_identity_mismatch")
var ErrLedgerAccessViolation = Define("ledger.access_violation")
var ErrAccountNotEligible = Define("account_not_eligible")
func LedgerIdempotencyConflict(msg string) error {
return classifiedError{
base: ErrDataConflict,
code: ErrLedgerIdempotencyConflict,
msg: ledgerErrorMessage(msg, ErrLedgerIdempotencyConflict),
reason: ReasonLedgerIdempotencyConflict,
}
}
func LedgerCommandIdentityMismatch(msg string) error {
return classifiedError{
base: ErrDataConflict,
code: ErrLedgerCommandIdentityMismatch,
msg: ledgerErrorMessage(msg, ErrLedgerCommandIdentityMismatch),
reason: ReasonLedgerCommandIdentityMismatch,
}
}
func LedgerAccessViolation(msg string) error {
return classifiedError{
base: ErrFailedPrecondition,
code: ErrLedgerAccessViolation,
msg: ledgerErrorMessage(msg, ErrLedgerAccessViolation),
reason: ReasonLedgerAccessViolation,
}
}
func AccountNotEligible(msg string) error {
return classifiedError{
base: ErrFailedPrecondition,
code: ErrAccountNotEligible,
msg: ledgerErrorMessage(msg, ErrAccountNotEligible),
reason: ReasonAccountNotEligible,
}
}
func ledgerErrorMessage(msg string, fallback error) string {
msg = strings.TrimSpace(msg)
if msg != "" {
return msg
}
if fallback == nil {
return ""
}
return fallback.Error()
}