Documentation
¶
Index ¶
- Variables
- func As(err error, target interface{}) bool
- func Error(w http.ResponseWriter, message string, code int)
- func ErrorHandler(logger *zap.Logger) func(http.Handler) http.Handler
- func ErrorWithType(w http.ResponseWriter, message string, errType ErrorType, code int)
- func LogError(logger *zap.Logger, err error, requestID string)
- func SetLogger(logger *zap.Logger)
- func WriteError(w http.ResponseWriter, err *HapaxError)
- type ErrorType
- type HapaxError
- func NewAuthError(requestID string, message string, err error) *HapaxError
- func NewInternalError(requestID string, err error) *HapaxError
- func NewProviderError(requestID string, message string, err error) *HapaxError
- func NewRateLimitError(requestID string, retryAfter int) *HapaxError
- func NewValidationError(requestID string, message string, validationDetails map[string]interface{}) *HapaxError
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultLogger *zap.Logger
DefaultLogger is the default zap logger instance
Functions ¶
func Error ¶
func Error(w http.ResponseWriter, message string, code int)
Error is a drop-in replacement for http.Error
func ErrorHandler ¶
ErrorHandler wraps an http.Handler and provides error handling
func ErrorWithType ¶
func ErrorWithType(w http.ResponseWriter, message string, errType ErrorType, code int)
ErrorWithType is like Error but allows specifying the error type
func WriteError ¶
func WriteError(w http.ResponseWriter, err *HapaxError)
WriteError writes the error to the http.ResponseWriter
Types ¶
type HapaxError ¶
type HapaxError struct {
Type ErrorType `json:"type"`
Message string `json:"message"`
Code int `json:"-"`
RequestID string `json:"request_id"`
Details map[string]interface{} `json:"details,omitempty"`
// contains filtered or unexported fields
}
HapaxError is our custom error type that carries additional context
func NewAuthError ¶
func NewAuthError(requestID string, message string, err error) *HapaxError
NewAuthError creates a new authentication error
func NewInternalError ¶
func NewInternalError(requestID string, err error) *HapaxError
NewInternalError creates a new internal server error
func NewProviderError ¶
func NewProviderError(requestID string, message string, err error) *HapaxError
NewProviderError creates a new provider-related error
func NewRateLimitError ¶
func NewRateLimitError(requestID string, retryAfter int) *HapaxError
NewRateLimitError creates a new rate limit error
func NewValidationError ¶
func NewValidationError(requestID string, message string, validationDetails map[string]interface{}) *HapaxError
NewValidationError creates a new validation error
func (*HapaxError) Is ¶
func (e *HapaxError) Is(target error) bool
Is implements error matching for errors.Is
Click to show internal directories.
Click to hide internal directories.