106 lines
3.6 KiB
Go
106 lines
3.6 KiB
Go
package merrors
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
func Reason(err error) (string, bool) {
|
|
var reasoned interface {
|
|
Reason() string
|
|
}
|
|
if errors.As(err, &reasoned) {
|
|
reason := strings.TrimSpace(reasoned.Reason())
|
|
if reason != "" {
|
|
return reason, true
|
|
}
|
|
}
|
|
switch {
|
|
case errors.Is(err, ErrAMLSourceIdempotencyConflict):
|
|
return ReasonAMLSourceIdempotencyConflict, true
|
|
case errors.Is(err, ErrLedgerIdempotencyConflict):
|
|
return ReasonLedgerIdempotencyConflict, true
|
|
case errors.Is(err, ErrLedgerCommandIdentityMismatch):
|
|
return ReasonLedgerCommandIdentityMismatch, true
|
|
case errors.Is(err, ErrLedgerAccessViolation):
|
|
return ReasonLedgerAccessViolation, true
|
|
case errors.Is(err, ErrAccountNotEligible):
|
|
return ReasonAccountNotEligible, true
|
|
case errors.Is(err, ErrQuotationFeeConfigurationMissing):
|
|
return QuotationFeeConfigurationMissingCode, true
|
|
case errors.Is(err, ErrQuotationReplayMissing):
|
|
return QuotationReplayMissingCode, true
|
|
default:
|
|
return "", false
|
|
}
|
|
}
|
|
|
|
func FromReason(reason string, msg string) (error, bool) {
|
|
switch strings.TrimSpace(reason) {
|
|
case ReasonRouteNotFound:
|
|
return RouteNotFound(msg), true
|
|
case ReasonRouteAmbiguous:
|
|
return RouteAmbiguous(msg), true
|
|
case ReasonRouteDisabled:
|
|
return RouteDisabled(msg), true
|
|
case ReasonRouteInvalidSource:
|
|
return RouteInvalidSource(msg), true
|
|
case ReasonRouteDestinationNotFound:
|
|
return RouteDestinationNotFound(msg), true
|
|
case ReasonRouteDestinationInactive:
|
|
return RouteDestinationInactive(msg), true
|
|
case ReasonRouteDestinationCurrencyMismatch:
|
|
return RouteDestinationCurrencyMismatch(msg), true
|
|
case ReasonRouteDestinationOrgMismatch:
|
|
return RouteDestinationOrgMismatch(msg), true
|
|
case ReasonRouteDestinationAmbiguous:
|
|
return RouteDestinationAmbiguous(msg), true
|
|
case ReasonRouteDestinationOwnerMismatch:
|
|
return RouteDestinationOwnerMismatch(msg), true
|
|
case ReasonRouteActiveSourceConflict:
|
|
return RouteActiveSourceConflict(msg), true
|
|
case ReasonRouteDestinationTypeMismatch:
|
|
return RouteDestinationTypeMismatch(msg), true
|
|
case ReasonRouteDestinationRoleMismatch:
|
|
return RouteDestinationRoleMismatch(msg), true
|
|
case ReasonRouteIdempotencyConflict:
|
|
return RouteIdempotencyConflict(msg), true
|
|
case ReasonRouteVersionConflict:
|
|
return RouteVersionConflict(msg), true
|
|
case ReasonRouteInvalidState:
|
|
return RouteInvalidState(msg), true
|
|
case ReasonAMLSourceIdempotencyConflict:
|
|
return AMLSourceIdempotencyConflict(msg), true
|
|
case ReasonLedgerIdempotencyConflict:
|
|
return LedgerIdempotencyConflict(msg), true
|
|
case ReasonLedgerCommandIdentityMismatch:
|
|
return LedgerCommandIdentityMismatch(msg), true
|
|
case ReasonLedgerAccessViolation:
|
|
return LedgerAccessViolation(msg), true
|
|
case ReasonAccountNotEligible:
|
|
return AccountNotEligible(msg), true
|
|
case ReasonDocumentsReportOwned:
|
|
return DocumentsReportOwned(msg), true
|
|
case ReasonDocumentsQuotationExpired:
|
|
return DocumentsQuotationExpired(msg), true
|
|
case ReasonPaymentExecutionNotAccepted:
|
|
return PaymentExecutionNotAccepted(msg), true
|
|
case QuotationFeeConfigurationMissingCode:
|
|
return QuotationFeeConfigurationMissing(), true
|
|
case QuotationReplayMissingCode:
|
|
return QuotationReplayMissing(), true
|
|
case ReasonOrganizationProvisioningInProgress:
|
|
return OrganizationProvisioningInProgress(msg), true
|
|
case ReasonOrganizationAlreadyActive:
|
|
return OrganizationAlreadyActive(msg), true
|
|
case ReasonOrganizationProvisioningBlocked:
|
|
return OrganizationProvisioningBlocked(msg), true
|
|
case ReasonOrganizationOwnerMismatch:
|
|
return OrganizationOwnerMismatch(msg), true
|
|
case ReasonOrganizationNotOperatorProvisioned:
|
|
return OrganizationNotOperatorProvisioned(msg), true
|
|
default:
|
|
return nil, false
|
|
}
|
|
}
|