simbaErrors

package
v0.18.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2025 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidContentType = NewSimbaError(http.StatusBadRequest, "invalid content type", errors.New("invalid content type"))
	ErrInvalidRequest     = NewSimbaError(http.StatusUnprocessableEntity, "invalid request", errors.New("failed to decode request body"))
	ErrValidationError    = NewSimbaError(http.StatusBadRequest, "request validation failed", errors.New("validation error"))
	ErrUnauthorized       = NewSimbaError(http.StatusUnauthorized, "unauthorized", errors.New("failed to authorize request"))
	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 ErrorCodeProvider added in v0.17.1

type ErrorCodeProvider 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
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL