errs

package
v2.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
var (
	// ErrUnauthorized matches [CodeUnauthorized].
	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.

View Source
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

func Is

func Is(err error, code Code) bool

Is reports whether err is an *Error carrying the given code.

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"
	// CodeUnauthorized indicates an HTTP 401 response: the request was not
	// 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

func FromHTTPStatus(status int, body []byte) *Error

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 New

func New(code Code, message string) *Error

New returns an *Error with the given code and message.

func NewSentinel

func NewSentinel(code Code, message string) *Error

NewSentinel returns a semantic sentinel with the given category and message. Unlike New, it does not match an unrelated error carrying the same category.

func Wrap

func Wrap(code Code, message string, cause error) *Error

Wrap returns an *Error with the given code and message that wraps cause.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) Is

func (e *Error) Is(target error) bool

Is reports whether e matches target. Ordinary errors match another *Error with the same Code. A semantic sentinel matches only itself, a copy of itself, or an error that wraps that sentinel; matching otherwise delegates to the wrapped cause.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped cause, if any, so the error can be inspected with errors.Is and errors.As.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL