Documentation
¶
Index ¶
- func AbortWithCCProxyError(c *gin.Context, errorType ErrorType, message string)
- func AbortWithError(c *gin.Context, err error)
- func ErrorHandlerMiddleware() gin.HandlerFunc
- func ExtractProviderError(resp *http.Response, body []byte, provider string) error
- func GetRetryAfter(err error) *time.Duration
- func HandleError(c *gin.Context, err error)
- func HandleErrorWithStatus(c *gin.Context, statusCode int, err error)
- func IsRetryableError(err error) bool
- func Retry(ctx context.Context, fn RetryFunc) error
- func RetryWithBackoff(ctx context.Context, attempts int, delay time.Duration, fn RetryFunc) error
- func RetryWithConfig(ctx context.Context, config *RetryConfig, fn RetryFunc) error
- func WrapProviderError(err error, provider string) error
- type CCProxyError
- func ErrBadRequest(message string) *CCProxyError
- func ErrInternal(message string) *CCProxyError
- func ErrNotFound(resource string) *CCProxyError
- func ErrProviderError(provider string, err error) *CCProxyError
- func ErrRateLimit(retryAfter time.Duration) *CCProxyError
- func ErrUnauthorized(message string) *CCProxyError
- func FromProviderResponse(statusCode int, body []byte, provider string) *CCProxyError
- func New(errorType ErrorType, message string) *CCProxyError
- func NewAuthError(message string, cause error) *CCProxyError
- func NewForbiddenError(message string, cause error) *CCProxyError
- func NewNotFoundError(message string, cause error) *CCProxyError
- func NewRateLimitError(message string, cause error) *CCProxyError
- func NewValidationError(message string, cause error) *CCProxyError
- func Newf(errorType ErrorType, format string, args ...interface{}) *CCProxyError
- func Wrap(err error, errorType ErrorType, message string) *CCProxyError
- func Wrapf(err error, errorType ErrorType, format string, args ...interface{}) *CCProxyError
- func (e *CCProxyError) Error() string
- func (e *CCProxyError) Is(target error) bool
- func (e *CCProxyError) ToJSON() ([]byte, error)
- func (e *CCProxyError) Unwrap() error
- func (e *CCProxyError) WithCode(code string) *CCProxyError
- func (e *CCProxyError) WithDetails(details map[string]interface{}) *CCProxyError
- func (e *CCProxyError) WithProvider(provider string) *CCProxyError
- func (e *CCProxyError) WithRequestID(requestID string) *CCProxyError
- func (e *CCProxyError) WithRetryAfter(duration time.Duration) *CCProxyError
- func (e *CCProxyError) WriteHTTPResponse(w http.ResponseWriter)
- type CircuitBreaker
- type CircuitState
- type ErrorDetail
- type ErrorResponse
- type ErrorType
- type RetryConfig
- type RetryFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AbortWithCCProxyError ¶
AbortWithCCProxyError aborts with a CCProxyError
func AbortWithError ¶
AbortWithError aborts the request with an error
func ErrorHandlerMiddleware ¶
func ErrorHandlerMiddleware() gin.HandlerFunc
ErrorHandlerMiddleware returns a Gin middleware for handling errors
func ExtractProviderError ¶
ExtractProviderError extracts error information from provider response
func GetRetryAfter ¶
GetRetryAfter extracts retry after duration from error
func HandleError ¶
HandleError handles errors in Gin context
func HandleErrorWithStatus ¶
HandleErrorWithStatus handles errors with a specific status code
func IsRetryableError ¶
IsRetryableError checks if an error is retryable
func RetryWithBackoff ¶
RetryWithBackoff executes a function with exponential backoff
func RetryWithConfig ¶
func RetryWithConfig(ctx context.Context, config *RetryConfig, fn RetryFunc) error
RetryWithConfig executes a function with retry logic
func WrapProviderError ¶
WrapProviderError wraps a provider error with additional context
Types ¶
type CCProxyError ¶
type CCProxyError struct {
Type ErrorType `json:"type"`
Message string `json:"message"`
Code string `json:"code,omitempty"`
StatusCode int `json:"-"`
Details map[string]interface{} `json:"details,omitempty"`
Provider string `json:"provider,omitempty"`
RequestID string `json:"request_id,omitempty"`
Timestamp time.Time `json:"timestamp"`
Retryable bool `json:"retryable"`
RetryAfter *time.Duration `json:"-"`
// contains filtered or unexported fields
}
CCProxyError represents a standardized error for ccproxy
func ErrBadRequest ¶
func ErrBadRequest(message string) *CCProxyError
ErrBadRequest creates a bad request error
func ErrInternal ¶
func ErrInternal(message string) *CCProxyError
ErrInternal creates an internal error
func ErrNotFound ¶
func ErrNotFound(resource string) *CCProxyError
ErrNotFound creates a not found error
func ErrProviderError ¶
func ErrProviderError(provider string, err error) *CCProxyError
ErrProviderError creates a provider error
func ErrRateLimit ¶
func ErrRateLimit(retryAfter time.Duration) *CCProxyError
ErrRateLimit creates a rate limit error
func ErrUnauthorized ¶
func ErrUnauthorized(message string) *CCProxyError
ErrUnauthorized creates an unauthorized error
func FromProviderResponse ¶
func FromProviderResponse(statusCode int, body []byte, provider string) *CCProxyError
FromProviderResponse creates an error from provider response
func New ¶
func New(errorType ErrorType, message string) *CCProxyError
New creates a new CCProxyError
func NewAuthError ¶
func NewAuthError(message string, cause error) *CCProxyError
NewAuthError creates an authentication error
func NewForbiddenError ¶
func NewForbiddenError(message string, cause error) *CCProxyError
NewForbiddenError creates a forbidden error
func NewNotFoundError ¶
func NewNotFoundError(message string, cause error) *CCProxyError
NewNotFoundError creates a not found error
func NewRateLimitError ¶
func NewRateLimitError(message string, cause error) *CCProxyError
NewRateLimitError creates a rate limit error
func NewValidationError ¶
func NewValidationError(message string, cause error) *CCProxyError
NewValidationError creates a validation error
func Newf ¶
func Newf(errorType ErrorType, format string, args ...interface{}) *CCProxyError
Newf creates a new CCProxyError with formatted message
func Wrap ¶
func Wrap(err error, errorType ErrorType, message string) *CCProxyError
Wrap wraps an existing error
func Wrapf ¶
func Wrapf(err error, errorType ErrorType, format string, args ...interface{}) *CCProxyError
Wrapf wraps an existing error with formatted message
func (*CCProxyError) Error ¶
func (e *CCProxyError) Error() string
Error implements the error interface
func (*CCProxyError) Is ¶
func (e *CCProxyError) Is(target error) bool
Is checks if the error is of a specific type
func (*CCProxyError) ToJSON ¶
func (e *CCProxyError) ToJSON() ([]byte, error)
ToJSON converts error to JSON
func (*CCProxyError) Unwrap ¶
func (e *CCProxyError) Unwrap() error
Unwrap returns the wrapped error
func (*CCProxyError) WithCode ¶
func (e *CCProxyError) WithCode(code string) *CCProxyError
WithCode adds a code to the error
func (*CCProxyError) WithDetails ¶
func (e *CCProxyError) WithDetails(details map[string]interface{}) *CCProxyError
WithDetails adds details to the error
func (*CCProxyError) WithProvider ¶
func (e *CCProxyError) WithProvider(provider string) *CCProxyError
WithProvider adds provider information to the error
func (*CCProxyError) WithRequestID ¶
func (e *CCProxyError) WithRequestID(requestID string) *CCProxyError
WithRequestID adds request ID to the error
func (*CCProxyError) WithRetryAfter ¶
func (e *CCProxyError) WithRetryAfter(duration time.Duration) *CCProxyError
WithRetryAfter sets retry information
func (*CCProxyError) WriteHTTPResponse ¶
func (e *CCProxyError) WriteHTTPResponse(w http.ResponseWriter)
WriteHTTPResponse writes the error as HTTP response
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
CircuitBreaker provides circuit breaker functionality
func NewCircuitBreaker ¶
func NewCircuitBreaker(name string, maxFailures int, resetTimeout time.Duration) *CircuitBreaker
NewCircuitBreaker creates a new circuit breaker
func (*CircuitBreaker) Execute ¶
func (cb *CircuitBreaker) Execute(ctx context.Context, fn RetryFunc) error
Execute runs a function with circuit breaker protection
func (*CircuitBreaker) GetState ¶
func (cb *CircuitBreaker) GetState() string
GetState returns the current state name
func (*CircuitBreaker) GetStats ¶
func (cb *CircuitBreaker) GetStats() map[string]interface{}
GetStats returns circuit breaker statistics
type CircuitState ¶
type CircuitState int
CircuitState represents the state of a circuit breaker
const ( CircuitClosed CircuitState = iota CircuitOpen CircuitHalfOpen )
type ErrorDetail ¶
type ErrorDetail struct {
Type string `json:"type"`
Message string `json:"message"`
Code string `json:"code,omitempty"`
Details map[string]interface{} `json:"details,omitempty"`
}
ErrorDetail contains error details
type ErrorResponse ¶
type ErrorResponse struct {
Error ErrorDetail `json:"error"`
}
ErrorResponse represents the API error response format
func NewErrorResponse ¶
func NewErrorResponse(errorType ErrorType, message string) *ErrorResponse
NewErrorResponse creates a new error response
func (*ErrorResponse) WithCode ¶
func (e *ErrorResponse) WithCode(code string) *ErrorResponse
WithCode adds a code to the error response
func (*ErrorResponse) WithDetails ¶
func (e *ErrorResponse) WithDetails(details map[string]interface{}) *ErrorResponse
WithDetails adds details to the error response
type ErrorType ¶
type ErrorType string
ErrorType represents the type of error
const ( // Client errors (4xx) ErrorTypeBadRequest ErrorType = "bad_request" ErrorTypeForbidden ErrorType = "forbidden" ErrorTypeNotFound ErrorType = "not_found" ErrorTypeMethodNotAllowed ErrorType = "method_not_allowed" ErrorTypeConflict ErrorType = "conflict" ErrorTypeUnprocessableEntity ErrorType = "unprocessable_entity" ErrorTypeTooManyRequests ErrorType = "too_many_requests" // Server errors (5xx) ErrorTypeInternal ErrorType = "internal_error" ErrorTypeNotImplemented ErrorType = "not_implemented" ErrorTypeBadGateway ErrorType = "bad_gateway" ErrorTypeGatewayTimeout ErrorType = "gateway_timeout" // Custom errors ErrorTypeProviderError ErrorType = "provider_error" ErrorTypeTransformError ErrorType = "transform_error" ErrorTypeRoutingError ErrorType = "routing_error" ErrorTypeStreamingError ErrorType = "streaming_error" ErrorTypeConfigError ErrorType = "config_error" ErrorTypeValidationError ErrorType = "validation_error" ErrorTypeRateLimitError ErrorType = "rate_limit_error" ErrorTypeProxyError ErrorType = "proxy_error" ErrorTypeToolError ErrorType = "tool_error" ErrorTypeResourceExhausted ErrorType = "resource_exhausted" )
type RetryConfig ¶
type RetryConfig struct {
MaxAttempts int
InitialDelay time.Duration
MaxDelay time.Duration
Multiplier float64
Jitter bool
RetryableErrors []ErrorType
}
RetryConfig defines retry behavior
func DefaultRetryConfig ¶
func DefaultRetryConfig() *RetryConfig
DefaultRetryConfig returns default retry configuration