Documentation
¶
Index ¶
- func HandleError(w http.ResponseWriter, err error, statusCode int)
- type APIError
- func NewAPIError(errorType ErrorType, message string) *APIError
- func NewAPIErrorWithCode(errorType ErrorType, message, code string) *APIError
- func NewAPIErrorWithDetails(errorType ErrorType, message, details string) *APIError
- func NewAuthenticationError(message string) *APIError
- func NewAuthorizationError(message string) *APIError
- func NewConfigurationError(message string) *APIError
- func NewExternalError(message string) *APIError
- func NewInternalError(message string) *APIError
- func NewNotFoundError(message string) *APIError
- func NewValidationError(message string) *APIError
- func ValidateNonEmpty(slice interface{}, fieldName string) *APIError
- func ValidateRequired(value, fieldName string) *APIError
- type ErrorResponse
- type ErrorType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleError ¶
func HandleError(w http.ResponseWriter, err error, statusCode int)
HandleError writes a standardized error response to the HTTP response writer
Types ¶
type APIError ¶
type APIError struct { Type ErrorType `json:"type"` Message string `json:"message"` Code string `json:"code,omitempty"` Details string `json:"details,omitempty"` }
APIError represents a structured API error
func NewAPIError ¶
NewAPIError creates a new APIError
func NewAPIErrorWithCode ¶
NewAPIErrorWithCode creates a new APIError with a code
func NewAPIErrorWithDetails ¶
NewAPIErrorWithDetails creates a new APIError with details
func NewAuthenticationError ¶
NewAuthenticationError creates an authentication error
func NewAuthorizationError ¶
NewAuthorizationError creates an authorization error
func NewConfigurationError ¶
NewConfigurationError creates a configuration error
func NewExternalError ¶
NewExternalError creates an external service error
func NewInternalError ¶
NewInternalError creates an internal error
func NewNotFoundError ¶
NewNotFoundError creates a not found error
func NewValidationError ¶
NewValidationError creates a validation error
func ValidateNonEmpty ¶
ValidateNonEmpty checks if a slice is non-empty
func ValidateRequired ¶
ValidateRequired checks if a required field is present
type ErrorResponse ¶
type ErrorResponse struct {
Error APIError `json:"error"`
}
ErrorResponse represents the JSON error response format
type ErrorType ¶
type ErrorType string
ErrorType represents different types of errors
const ( ErrorTypeValidation ErrorType = "validation_error" ErrorTypeAuthentication ErrorType = "authentication_error" ErrorTypeAuthorization ErrorType = "authorization_error" ErrorTypeNotFound ErrorType = "not_found_error" ErrorTypeInternal ErrorType = "internal_error" ErrorTypeExternal ErrorType = "external_error" ErrorTypeConfiguration ErrorType = "configuration_error" )