Documentation
¶
Index ¶
- func CombineErrors(errors ...error) error
- func GetErrorCode(err error) string
- func GetHTTPStatus(err error) int
- func IsCode(err error, code string) bool
- func IsRetryable(err error) bool
- func IsType(err error, errorType ErrorType) bool
- type Error
- func BadRequestError(code, message string) *Error
- func ConflictError(code, message string) *Error
- func ExternalError(code, message string) *Error
- func ForbiddenError(code, message string) *Error
- func InternalError(code, message string) *Error
- func NewError(errorType ErrorType, code, message string) *Error
- func NotFoundError(code, message string) *Error
- func RateLimitError(code, message string) *Error
- func ServiceUnavailableError(code, message string) *Error
- func TimeoutError(code, message string) *Error
- func UnauthorizedError(code, message string) *Error
- func ValidationError(code, message string) *Error
- func Wrap(err error, errorType ErrorType, code, message string) *Error
- func (e *Error) Error() string
- func (e *Error) Is(target error) bool
- func (e *Error) JSON() string
- func (e *Error) MarkRetryable() *Error
- func (e *Error) Unwrap() error
- func (e *Error) WithCause(cause error) *Error
- func (e *Error) WithComponent(component string) *Error
- func (e *Error) WithDetails(details string) *Error
- func (e *Error) WithHTTPStatus(status int) *Error
- func (e *Error) WithMetadata(key string, value interface{}) *Error
- func (e *Error) WithOperation(operation string) *Error
- func (e *Error) WithRequestID(requestID string) *Error
- func (e *Error) WithUserID(userID string) *Error
- type ErrorChain
- func (ec *ErrorChain) Add(err *Error)
- func (ec *ErrorChain) AddError(err error, errorType ErrorType, code, message string)
- func (ec *ErrorChain) Count() int
- func (ec *ErrorChain) Error() string
- func (ec *ErrorChain) Filter(errorType ErrorType) []*Error
- func (ec *ErrorChain) First() *Error
- func (ec *ErrorChain) HasErrors() bool
- func (ec *ErrorChain) JSON() string
- func (ec *ErrorChain) Last() *Error
- type ErrorHandler
- type ErrorType
- type StackFrame
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CombineErrors ¶
CombineErrors combines multiple errors into an error chain
func GetHTTPStatus ¶
GetHTTPStatus returns the HTTP status code for an error
Types ¶
type Error ¶
type Error struct {
Type ErrorType `json:"type"`
Code string `json:"code"`
Message string `json:"message"`
Details string `json:"details,omitempty"`
Cause error `json:"-"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
Timestamp time.Time `json:"timestamp"`
StackTrace []StackFrame `json:"stack_trace,omitempty"`
RequestID string `json:"request_id,omitempty"`
UserID string `json:"user_id,omitempty"`
Operation string `json:"operation,omitempty"`
Component string `json:"component,omitempty"`
Retryable bool `json:"retryable"`
HTTPStatus int `json:"http_status,omitempty"`
}
Error represents a structured error with additional context
func BadRequestError ¶
BadRequestError creates a bad request error
func ConflictError ¶
ConflictError creates a conflict error
func ExternalError ¶
ExternalError creates an external service error
func ForbiddenError ¶
ForbiddenError creates a forbidden error
func InternalError ¶
InternalError creates an internal error
func NotFoundError ¶
NotFoundError creates a not found error
func RateLimitError ¶
RateLimitError creates a rate limit error
func ServiceUnavailableError ¶
ServiceUnavailableError creates a service unavailable error
func TimeoutError ¶
TimeoutError creates a timeout error
func UnauthorizedError ¶
UnauthorizedError creates an unauthorized error
func ValidationError ¶
ValidationError creates a validation error
func (*Error) MarkRetryable ¶
MarkRetryable marks the error as retryable
func (*Error) WithComponent ¶
WithComponent adds a component name to the error
func (*Error) WithDetails ¶
WithDetails adds details to the error
func (*Error) WithHTTPStatus ¶
WithHTTPStatus adds an HTTP status code to the error
func (*Error) WithMetadata ¶
WithMetadata adds metadata to the error
func (*Error) WithOperation ¶
WithOperation adds an operation name to the error
func (*Error) WithRequestID ¶
WithRequestID adds a request ID to the error
func (*Error) WithUserID ¶
WithUserID adds a user ID to the error
type ErrorChain ¶
type ErrorChain struct {
Errors []*Error `json:"errors"`
}
ErrorChain represents a chain of errors for aggregation
func (*ErrorChain) AddError ¶
func (ec *ErrorChain) AddError(err error, errorType ErrorType, code, message string)
AddError adds a regular error to the chain by wrapping it
func (*ErrorChain) Count ¶
func (ec *ErrorChain) Count() int
Count returns the number of errors in the chain
func (*ErrorChain) Error ¶
func (ec *ErrorChain) Error() string
Error implements the error interface
func (*ErrorChain) Filter ¶
func (ec *ErrorChain) Filter(errorType ErrorType) []*Error
Filter returns errors of a specific type
func (*ErrorChain) First ¶
func (ec *ErrorChain) First() *Error
First returns the first error in the chain
func (*ErrorChain) HasErrors ¶
func (ec *ErrorChain) HasErrors() bool
HasErrors returns true if there are any errors in the chain
func (*ErrorChain) Last ¶
func (ec *ErrorChain) Last() *Error
Last returns the last error in the chain
type ErrorHandler ¶
ErrorHandler provides utilities for error handling
func NewErrorHandler ¶
func NewErrorHandler(component string, logger func(error)) *ErrorHandler
NewErrorHandler creates a new error handler
func (*ErrorHandler) Handle ¶
func (eh *ErrorHandler) Handle(err error, sanitize bool) error
Handle handles an error by logging it and optionally returning a sanitized version
func (*ErrorHandler) Recover ¶
func (eh *ErrorHandler) Recover() error
Recover recovers from panics and converts them to errors
func (*ErrorHandler) SafeExecute ¶
func (eh *ErrorHandler) SafeExecute(fn func() error) (err error)
SafeExecute executes a function and handles any panics
type ErrorType ¶
type ErrorType string
ErrorType represents different types of errors
const ( ErrorTypeValidation ErrorType = "validation" ErrorTypeNotFound ErrorType = "not_found" ErrorTypeForbidden ErrorType = "forbidden" ErrorTypeConflict ErrorType = "conflict" ErrorTypeInternal ErrorType = "internal" ErrorTypeExternal ErrorType = "external" ErrorTypeTimeout ErrorType = "timeout" ErrorTypeRateLimit ErrorType = "rate_limit" ErrorTypeBadRequest ErrorType = "bad_request" )
type StackFrame ¶
type StackFrame struct {
Function string `json:"function"`
File string `json:"file"`
Line int `json:"line"`
}
StackFrame represents a stack frame