Documentation
¶
Overview ¶
Package xerr is the error model of the API. A CodeError carries one of the numeric codes of err_code.go and a message, which is all a client learns of a failure: a response carries the code and message of the first CodeError in the error chain, never the rest of the error text. Wrapf and Errorf attach a code while keeping the underlying error reachable for errors.Is and errors.As and for the log (Detail). Clients switch on the numeric values, so existing codes never change.
Index ¶
Constants ¶
const ( BandIdentity uint32 = 110000 // accounts, auth, devices, verification BandBilling uint32 = 120000 // orders, payments, coupons, wallet BandSubscription uint32 = 130000 // plans, user subscriptions, quota BandNetwork uint32 = 140000 // servers, nodes, traffic BandSupport uint32 = 150000 // tickets, announcements, ads, documents BandPlatform uint32 = 160000 // system settings, tasks, logs BandNotification uint32 = 170000 // telegram, broadcast channels )
Domain bands for NEW error codes (ADR-001: modules evolve toward separate services, so codes must not collide across independently-released domains). Every code introduced from 2026-07-25 on must be allocated inside its owning module's band; the pre-existing codes below are frozen where they are — clients switch on the numeric values, renumbering is a breaking change. TestErrorCodeSegmentation enforces both rules.
const ( SUCCESS uint32 = 200 ERROR uint32 = 500 )
General error code
const ( DatabaseQueryError uint32 = 10001 DatabaseUpdateError uint32 = 10002 DatabaseInsertError uint32 = 10003 DatabaseDeletedError uint32 = 10004 )
Database error
const ( UserExist uint32 = 20001 UserNotExist uint32 = 20002 UserPasswordError uint32 = 20003 UserDisabled uint32 = 20004 InsufficientBalance uint32 = 20005 StopRegister uint32 = 20006 TelegramNotBound uint32 = 20007 UserNotBindOauth uint32 = 20008 InviteCodeError uint32 = 20009 UserCommissionNotEnough uint32 = 20010 )
User error
const ( NodeExist uint32 = 30001 NodeNotExist uint32 = 30002 NodeGroupExist uint32 = 30003 NodeGroupNotExist uint32 = 30004 NodeGroupNotEmpty uint32 = 30005 )
Node error
const ( InvalidParams uint32 = 400 TooManyRequests uint32 = 401 ErrorTokenEmpty uint32 = 40002 ErrorTokenInvalid uint32 = 40003 ErrorTokenExpire uint32 = 40004 InvalidAccess uint32 = 40005 InvalidCiphertext uint32 = 40006 SecretIsEmpty uint32 = 40007 )
Request error
const ( CouponNotExist uint32 = 50001 // Coupon does not exist CouponAlreadyUsed uint32 = 50002 // Coupon has already been used CouponNotApplicable uint32 = 50003 // Coupon does not match the order or conditions CouponInsufficientUsage uint32 = 50004 // Coupon has insufficient remaining uses CouponExpired uint32 = 50005 // Coupon is expired CouponDisabled uint32 = 50006 // Coupon is disabled )
const ( SubscribeExpired uint32 = 60001 SubscribeNotAvailable uint32 = 60002 UserSubscribeExist uint32 = 60003 SubscribeIsUsedError uint32 = 60004 SingleSubscribeModeExceedsLimit uint32 = 60005 SubscribeQuotaLimit uint32 = 60006 SubscribeOutOfStock uint32 = 60007 )
const ( // OAuthStateInvalid: the callback's state is unknown, used or expired. OAuthStateInvalid uint32 = 110001 // OAuthProviderError: the provider rejected the sign-in or could not be reached. OAuthProviderError uint32 = 110002 // OAuthCallbackInvalid: the callback payload is malformed or its signature does not verify. OAuthCallbackInvalid uint32 = 110003 // OAuthCallbackExpired: the signed callback is older than its validity window. OAuthCallbackExpired uint32 = 110004 // OAuthCallbackReplayed: the signed callback has already been redeemed. OAuthCallbackReplayed uint32 = 110005 // OAuthProviderMisconfigured: the stored provider configuration is unusable. OAuthProviderMisconfigured uint32 = 110006 TelegramBotUnavailable uint32 = 110007 // DemoModeRestricted: the operation is not allowed on the demo instance. DemoModeRestricted uint32 = 110008 // SenderTestFailed: the test message of a sender platform could not be sent. SenderTestFailed uint32 = 110009 // EmailIdentityAmbiguous: an email address matches more than one binding. EmailIdentityAmbiguous uint32 = 110010 )
Identity band: accounts, sign-in, OAuth and verification.
const ( SendSmsError uint32 = 90002 SmsNotEnabled uint32 = 90003 EmailNotEnabled uint32 = 90004 )
const ( GetAuthenticatorError uint32 = 90005 AuthenticatorNotSupportedError uint32 = 90006 TelephoneAreaCodeIsEmpty uint32 = 90007 TodaySendCountExceedsLimit uint32 = 90015 )
const ( PasswordIsEmpty uint32 = 90008 AreaCodeIsEmpty uint32 = 90009 PasswordOrVerificationCodeRequired uint32 = 90010 EmailExist uint32 = 90011 TelephoneExist uint32 = 90012 DeviceExist uint32 = 90013 TelephoneError uint32 = 90014 )
const ( DeviceNotExist uint32 = 90017 UseridNotMatch uint32 = 90018 )
const ( OrderNotExist uint32 = 61001 PaymentMethodNotFound uint32 = 61002 OrderStatusError uint32 = 61003 InsufficientOfPeriod uint32 = 61004 ExistAvailableTraffic uint32 = 61005 )
const ( PaymentNotifyURLNotConfigured uint32 = 120001 UnsupportedPaymentPlatform uint32 = 120002 InvalidPaymentConfig uint32 = 120003 PaymentPlatformImmutable uint32 = 120004 PaymentMethodHasPendingOrders uint32 = 120005 PaymentMethodInternal uint32 = 120006 InvalidPaymentFee uint32 = 120007 PaymentStatusUnconfirmed uint32 = 120008 InvalidInitialOrderStatus uint32 = 120009 InvalidOrderTransition uint32 = 120010 TradeNoRequired uint32 = 120011 InvalidOrderCloseRequest uint32 = 120012 CouponUsedCountImmutable uint32 = 120013 InvalidCoupon uint32 = 120014 InvalidCouponDiscount uint32 = 120015 InvalidCouponType uint32 = 120016 WithdrawalAlreadyReviewed uint32 = 120017 )
Billing band (BandBilling): orders, payments, coupons and the wallet. The messages keep the identifiers these failures carried before they had codes, so clients matching the message keep working.
const ( // SubscriptionStatusChanged: the subscription is no longer in the status // the request was made against. SubscriptionStatusChanged uint32 = 130001 // SubscriptionStatusNotToggleable: only an active or a stopped // subscription can be stopped or resumed. SubscriptionStatusNotToggleable uint32 = 130002 )
Subscription band (BandSubscription): plans, user subscriptions and quota.
const (
DebugModeError uint32 = 90001
)
const (
QueueEnqueueError uint32 = 80001
)
const ( // SettingsSavedNotApplied: the settings are stored, but the subsystem // that uses them could not be reloaded; they take effect after a // successful reload or a restart. SettingsSavedNotApplied uint32 = 160001 )
Platform band (BandPlatform): system settings, tasks and logs.
const (
VerifyCodeError uint32 = 70001
)
Variables ¶
var ErrNotModified = errors.New("304 Not Modified")
ErrNotModified reports that the client's cached copy is current: the handler answers 304 Not Modified instead of a body.
Functions ¶
func CodeOf ¶ added in v1.21.0
CodeOf returns the code the client receives for err: the first code in its chain, or ERROR when it carries none.
func Detail ¶ added in v1.21.0
Detail describes err for a log line: its message, plus the cause of any code in the chain whose message does not already include that cause.
func Errorf ¶ added in v1.21.0
Errorf returns an error carrying code with a formatted context message, for failures that have no underlying error to wrap.
func IsGeneric ¶ added in v1.21.0
IsGeneric reports whether code only says that something failed (ERROR or a database failure) rather than what the client did wrong.
func MapErrMsg ¶
MapErrMsg returns the client-facing message of errCode, or that of ERROR for a code without one.
func Wrapf ¶ added in v1.21.0
Wrapf reports err under code, prefixed with a formatted context message.
A generic code (see IsGeneric) never replaces a code err already carries: the layer that produced err knew the specific failure, such as an exhausted coupon inside a transaction, and that is what the client must see. err stays reachable through errors.Is and errors.As either way. Wrapf returns nil when err is nil.
Types ¶
type CodeError ¶
type CodeError struct {
// contains filtered or unexported fields
}
CodeError is an error with a client-facing code and message.
func NewErrCode ¶
NewErrCode returns an error with errCode and the code's message.
func NewErrCodeMsg ¶
NewErrCodeMsg returns an error with errCode and a message of its own, which the client receives in place of the code's usual message.
func (*CodeError) GetErrCode ¶
GetErrCode returns the error code displayed to the front end