simbaErrors

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2025 License: MIT Imports: 8 Imported by: 0

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) Error

func (e *HTTPError) Error() string

Error implements the error interface and returns the full error details

func (*HTTPError) HasValidationErrors

func (e *HTTPError) HasValidationErrors() bool

HasValidationErrors checks if there are validation errors

func (*HTTPError) Unwrap

func (e *HTTPError) Unwrap() error

Unwrap returns the underlying error

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

Jump to

Keyboard shortcuts

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