Documentation
¶
Overview ¶
Package apierrors provides unified error handling for CipherSwarm API interactions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetStatusCode ¶
GetStatusCode extracts the HTTP status code from an API error. Returns 0 if the error is not an APIError.
func IsCircuitOpen ¶ added in v0.6.2
IsCircuitOpen checks if the error is caused by an open circuit breaker.
func IsGoneError ¶
IsGoneError checks if the error is a 410 Gone error.
func IsNotFoundError ¶
IsNotFoundError checks if the error is a 404 Not Found error.
Types ¶
type ErrorSender ¶
ErrorSender is a function type for sending errors to the server. This allows dependency injection for testing and prevents circular imports.
type Handler ¶
type Handler struct {
// SendError is the function to call for sending errors to the server.
// If nil, errors are only logged locally.
SendError ErrorSender
}
Handler provides unified error handling for API operations.
func (*Handler) Handle ¶
Handle processes an API error according to the provided options. It extracts error details from API error types and logs/reports appropriately. Returns the original error for chaining.
type Options ¶
type Options struct {
// Message is the context message to log with the error.
Message string
// Severity is the severity level for the error report.
Severity api.Severity
// SendToServer indicates whether to send the error to the server.
SendToServer bool
// LogAuthContext adds agent_id, api_url, has_token to auth-related errors.
LogAuthContext bool
}
Options configures how an error should be handled.
func DefaultOptions ¶
DefaultOptions returns Options with sensible defaults.