errors

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 27, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

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

func NewAPIError(errorType ErrorType, message string) *APIError

NewAPIError creates a new APIError

func NewAPIErrorWithCode

func NewAPIErrorWithCode(errorType ErrorType, message, code string) *APIError

NewAPIErrorWithCode creates a new APIError with a code

func NewAPIErrorWithDetails

func NewAPIErrorWithDetails(errorType ErrorType, message, details string) *APIError

NewAPIErrorWithDetails creates a new APIError with details

func NewAuthenticationError

func NewAuthenticationError(message string) *APIError

NewAuthenticationError creates an authentication error

func NewAuthorizationError

func NewAuthorizationError(message string) *APIError

NewAuthorizationError creates an authorization error

func NewConfigurationError

func NewConfigurationError(message string) *APIError

NewConfigurationError creates a configuration error

func NewExternalError

func NewExternalError(message string) *APIError

NewExternalError creates an external service error

func NewInternalError

func NewInternalError(message string) *APIError

NewInternalError creates an internal error

func NewNotFoundError

func NewNotFoundError(message string) *APIError

NewNotFoundError creates a not found error

func NewValidationError

func NewValidationError(message string) *APIError

NewValidationError creates a validation error

func ValidateNonEmpty

func ValidateNonEmpty(slice interface{}, fieldName string) *APIError

ValidateNonEmpty checks if a slice is non-empty

func ValidateRequired

func ValidateRequired(value, fieldName string) *APIError

ValidateRequired checks if a required field is present

func (*APIError) Error

func (e *APIError) Error() string

Error implements the error interface

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

Jump to

Keyboard shortcuts

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