Documentation
¶
Overview ¶
Package errs defines the typed error model shared by every webullapi4go package.
An Error carries a stable Code for programmatic classification, a human-readable message, and an optional wrapped cause. It participates in errors.Is and errors.As through Error.Unwrap and Error.Is, so callers can branch on a category without matching strings.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnauthorized = New(CodeUnauthorized, "unauthorized") // ErrForbidden matches [CodeForbidden]. ErrForbidden = New(CodeForbidden, "forbidden") // ErrInvalidToken matches [CodeInvalidToken]. ErrInvalidToken = New(CodeInvalidToken, "invalid token") // ErrRateLimited matches [CodeRateLimited]. ErrRateLimited = New(CodeRateLimited, "rate limited") // ErrServer matches [CodeServer]. ErrServer = New(CodeServer, "server error") // ErrInvalidTransition matches [CodeInvalidTransition]. ErrInvalidTransition = New(CodeInvalidTransition, "invalid state transition") // ErrNotInitialized matches [CodeNotInitialized]. ErrNotInitialized = New(CodeNotInitialized, "client not initialized") // ErrValidation matches [CodeValidation]. ErrValidation = New(CodeValidation, "validation failed") // ErrOrderGuardrail matches [CodeOrderGuardrail]. ErrOrderGuardrail = New(CodeOrderGuardrail, "order guardrail exceeded") // ErrSubscriptionExpired matches [CodeAuth] for subscription/tocket expiry in // streaming event clients. ErrSubscriptionExpired = NewSentinel(CodeAuth, "subscription expired") // ErrConnectionLimitExceeded matches [CodeTransport] for gRPC-stream connection // limit rejection (at most 5 concurrent connections per App Key). ErrConnectionLimitExceeded = NewSentinel(CodeTransport, "connection limit exceeded") )
Sentinel errors for the HTTP status classifications returned by FromHTTPStatus. errors.Is matches them by Code, so callers can write errors.Is(err, errs.ErrUnauthorized) without depending on message text.
var ErrUnsupported = Wrap(CodeUnsupported, "operation not supported", errors.ErrUnsupported)
ErrUnsupported is the sentinel for operations the SDK does not support. It also satisfies errors.Is(err, errors.ErrUnsupported).
Functions ¶
Types ¶
type Code ¶
type Code string
Code is a stable, machine-readable classification of an error.
const ( // CodeInvalidConfig indicates that the client configuration is invalid. CodeInvalidConfig Code = "invalid_config" // CodeUnsupported indicates an operation the SDK does not support. CodeUnsupported Code = "unsupported" // CodeAuth indicates an authentication, signing, or token failure. CodeAuth Code = "auth" // CodeTransport indicates a network or HTTP transport failure. CodeTransport Code = "transport" // CodeAPI indicates a non-success response returned by the Webull API. CodeAPI Code = "api" // authenticated. CodeUnauthorized Code = "UNAUTHORIZED" // CodeForbidden indicates an HTTP 403 response: the caller lacks the // permission or data subscription required by the endpoint. CodeForbidden Code = "FORBIDDEN" // CodeInvalidToken indicates an HTTP 417 response: the access token is // missing, expired, or otherwise invalid. CodeInvalidToken Code = "INVALID_TOKEN" // CodeRateLimited indicates an HTTP 429 response: the request exceeded the // endpoint's rate limit. CodeRateLimited Code = "RATE_LIMITED" // CodeServer indicates an HTTP 5xx response: the Webull service failed. CodeServer Code = "SERVER_ERROR" // CodeInvalidTransition indicates a request that is invalid given the // current state of the target resource (for example cancelling an already-filled // order). CodeInvalidTransition Code = "invalid_transition" // CodeNotInitialized indicates a client or resource that is required to be // initialized has not been (for example, a stream or events client whose // Run method has not been called). CodeNotInitialized Code = "not_initialized" // CodeValidation indicates an input value failed validation (distinct from // a client configuration error). CodeValidation Code = "validation" // CodeOrderGuardrail indicates an order was rejected because it exceeded a // risk guardrail (max quantity, max notional, or similar). CodeOrderGuardrail Code = "order_guardrail" )
type Error ¶
type Error struct {
// Code is the stable error category.
Code Code
// Message is a human-readable description of what went wrong.
Message string
// Status is the HTTP status code of the response that caused the error, or
// zero when the error did not originate from an HTTP response.
Status int
// Err is the optional underlying cause.
Err error
}
Error is the SDK's typed error. It is safe to return by value as *Error and to compare by Code via errors.Is.
func FromHTTPStatus ¶
FromHTTPStatus maps a non-2xx HTTP response status to a typed Error. When the response body carries an API error message (a JSON object with a "message", "msg", "error_msg", "errorMessage", or "error_description" field), that message is included; otherwise the raw body is included when it is short enough to be readable, and the standard status text is used as a last resort. The returned error's Error.Status is always status.
func NewSentinel ¶
NewSentinel returns a semantic sentinel with the given category and message. Unlike New, it does not match an unrelated error carrying the same category.