apierrors

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

func GetStatusCode(err error) int

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

func IsCircuitOpen(err error) bool

IsCircuitOpen checks if the error is caused by an open circuit breaker.

func IsGoneError

func IsGoneError(err error) bool

IsGoneError checks if the error is a 410 Gone error.

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError checks if the error is a 404 Not Found error.

Types

type ErrorSender

type ErrorSender func(ctx context.Context, message string, severity api.Severity)

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

func (h *Handler) Handle(ctx context.Context, err error, opts Options) error

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.

func (*Handler) HandleWithSeverity

func (h *Handler) HandleWithSeverity(ctx context.Context, err error, message string, severity api.Severity) error

HandleWithSeverity handles an error with a specific severity level.

func (*Handler) LogOnly

func (h *Handler) LogOnly(ctx context.Context, err error, message string) error

LogOnly logs an error without sending to the server. Useful for preventing infinite recursion when error sending fails.

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

func DefaultOptions(message string) Options

DefaultOptions returns Options with sensible defaults.

Jump to

Keyboard shortcuts

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