Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidContentType = NewSimbaError(http.StatusBadRequest, "invalid content type", errors.New("invalid content type")) ErrInvalidRequestBody = NewSimbaError(http.StatusBadRequest, "invalid request body", errors.New("failed to decode request body")) ErrUnexpected = NewSimbaError(http.StatusInternalServerError, "unexpected error", errors.New("unexpected error occurred")) )
Predefined errors for common scenarios
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 DetailProvider ¶ added in v0.17.0
type DetailProvider interface {
Details() any
}
type ErrorProvider ¶ added in v0.17.0
type ErrorProvider interface {
ErrorCode() string
}
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 code
ErrorCode string `json:"errorCode,omitempty" example:"123-123" required:"false"`
// Error message
Message string `json:"message,omitempty" example:"Validation failed"`
// Validation errors
Details any `json:"details,omitempty" required:"false"`
}
ErrorResponse defines the structure of an error message
type PublicMessageProvider ¶ added in v0.17.0
type PublicMessageProvider interface {
PublicMessage() string
}
type SimbaError ¶ added in v0.17.0
type SimbaError struct {
// contains filtered or unexported fields
}
func NewSimbaError ¶ added in v0.17.0
func NewSimbaError(statusCode int, publicMessage string, err error) *SimbaError
func (*SimbaError) Details ¶ added in v0.17.0
func (e *SimbaError) Details() any
func (*SimbaError) Error ¶ added in v0.17.0
func (e *SimbaError) Error() string
func (*SimbaError) PublicMessage ¶ added in v0.17.0
func (e *SimbaError) PublicMessage() string
func (*SimbaError) StatusCode ¶ added in v0.17.0
func (e *SimbaError) StatusCode() int
func (*SimbaError) Unwrap ¶ added in v0.17.0
func (e *SimbaError) Unwrap() error
func (*SimbaError) WithDetails ¶ added in v0.17.0
func (e *SimbaError) WithDetails(details any) *SimbaError
type StatusCodeProvider ¶ added in v0.17.0
type StatusCodeProvider interface {
StatusCode() int
}
Click to show internal directories.
Click to hide internal directories.