Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleUnexpectedError ¶
func HandleUnexpectedError(w http.ResponseWriter)
HandleUnexpectedError is a helper function for handling unexpected errors
func WriteError ¶
func WriteError(w http.ResponseWriter, r *http.Request, err error)
WriteError is a helper function for handling errors in HTTP handlers
Types ¶
type ErrorResponse ¶
type ErrorResponse struct {
// Timestamp of the error
Timestamp time.Time `json:"timestamp" example:"2021-01-01T12:00:00Z"`
// HTTP status code
Status int `json:"status" example:"400"`
// HTTP error type
Error string `json:"error" example:"Bad Request"`
// Path of the Request
Path string `json:"path" example:"/api/v1/users"`
// Method of the Request
Method string `json:"method" example:"GET"`
// Request ID
RequestID string `json:"requestId,omitempty" example:"123e4567-e89b-12d3-a456-426614174000" required:"false"`
// Error message
Message string `json:"message,omitempty" example:"Validation failed"`
// Validation errors
ValidationErrors []ValidationError `json:"validationErrors,omitempty" required:"false"`
}
ErrorResponse defines the structure of an error message
func NewErrorResponse ¶
func NewErrorResponse(r *http.Request, status int, message string, validationErrors ...ValidationError) *ErrorResponse
NewErrorResponse creates a new ErrorResponse instance with the given status and message
type HTTPError ¶
type HTTPError struct {
HttpStatusCode int
PublicMessage string
ValidationErrors ValidationErrors
// contains filtered or unexported fields
}
func NewHttpError ¶
func NewHttpError(httpStatusCode int, publicMessage string, err error, validationErrors ...ValidationError) *HTTPError
NewHttpError creates a new ApiError
func WrapError ¶
func WrapError(httpStatusCode int, err error, publicMessage string, validationErrors ...ValidationError) *HTTPError
WrapError wraps an error with an HTTP status code
func (*HTTPError) HasValidationErrors ¶
HasValidationErrors checks if there are validation errors
type ParameterType ¶
type ParameterType string
const ( ParameterTypeHeader ParameterType = "header" ParameterTypeCookie ParameterType = "cookie" ParameterTypePath ParameterType = "path" ParameterTypeQuery ParameterType = "query" ParameterTypeBody ParameterType = "body" )
func (ParameterType) String ¶
func (p ParameterType) String() string
type ValidationError ¶
type ValidationError struct {
// Parameter or field that failed validation
Parameter string `json:"parameter" example:"name"`
// Type indicates where the parameter was located (header, path, query, body)
Type ParameterType `json:"type" example:"query"`
// Error message describing the validation error
Message string `json:"message" example:"name is required"`
}
ValidationError defines the interface for a validation error
type ValidationErrors ¶
type ValidationErrors []ValidationError
ValidationErrors represents multiple validation errors
func (ValidationErrors) Error ¶
func (ve ValidationErrors) Error() string
Error implements the error interface
Click to show internal directories.
Click to hide internal directories.