errors

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package errors provides consistent error handling and response formatting for the API

Index

Constants

View Source
const (
	ErrCodeValidation      = "VALIDATION_ERROR"
	ErrCodeDatabase        = "DATABASE_ERROR"
	ErrCodeUnauthorized    = "UNAUTHORIZED"
	ErrCodeForbidden       = "FORBIDDEN"
	ErrCodeNotFound        = "NOT_FOUND"
	ErrCodeConflict        = "CONFLICT"
	ErrCodeInternal        = "INTERNAL_ERROR"
	ErrCodeBadRequest      = "BAD_REQUEST"
	ErrCodeUnprocessable   = "UNPROCESSABLE_ENTITY"
	ErrCodeTooManyRequests = "TOO_MANY_REQUESTS"

	// Channel Registration specific error codes
	ErrCodeRegistrationsDisabled  = "REGISTRATIONS_DISABLED"
	ErrCodeUserRestricted         = "USER_RESTRICTED"
	ErrCodeIrcIdleCheckFailed     = "IRC_IDLE_CHECK_FAILED"
	ErrCodePendingExists          = "PENDING_REGISTRATION_EXISTS"
	ErrCodeChannelLimitExceeded   = "CHANNEL_LIMIT_EXCEEDED"
	ErrCodeChannelLimitReached    = "CHANNEL_LIMIT_REACHED"
	ErrCodeCooldownActive         = "COOLDOWN_ACTIVE"
	ErrCodeCooldownPeriod         = "COOLDOWN_PERIOD"
	ErrCodeInsufficientSupporters = "INSUFFICIENT_SUPPORTERS"
	ErrCodeInvalidChannelName     = "INVALID_CHANNEL_NAME"
	ErrCodeInvalidDescription     = "INVALID_DESCRIPTION"
	ErrCodeChannelNameExists      = "CHANNEL_NAME_EXISTS"
	ErrCodeChannelAlreadyExists   = "CHANNEL_ALREADY_EXISTS"
	ErrCodeInvalidSupporterUser   = "INVALID_SUPPORTER_USER"
	ErrCodeInvalidSupporters      = "INVALID_SUPPORTERS"
	ErrCodeSelfSupportNotAllowed  = "SELF_SUPPORT_NOT_ALLOWED"
	ErrCodeDuplicateSupporters    = "DUPLICATE_SUPPORTERS"
	ErrCodeInactiveUser           = "INACTIVE_USER"
	ErrCodeDatabaseError          = "DATABASE_ERROR"

	// Supporter validation specific error codes
	ErrCodeSupportersTooNew      = "SUPPORTERS_TOO_NEW"
	ErrCodeSupportersRestricted  = "SUPPORTERS_RESTRICTED"
	ErrCodeSupportersEmailLocked = "SUPPORTERS_EMAIL_LOCKED"
	ErrCodeSupportersOverLimit   = "SUPPORTERS_OVER_LIMIT"
)

Error codes for consistent error identification

Variables

This section is empty.

Functions

func HandleBadRequestError

func HandleBadRequestError(c echo.Context, message string) error

HandleBadRequestError handles malformed request errors

func HandleConflictError

func HandleConflictError(c echo.Context, message string) error

HandleConflictError handles resource conflict errors

func HandleDatabaseError

func HandleDatabaseError(c echo.Context, err error) error

HandleDatabaseError handles database errors by logging details but returning generic message

func HandleForbiddenError

func HandleForbiddenError(c echo.Context, message string) error

HandleForbiddenError handles authorization failures (user is authenticated but lacks permission)

func HandleInternalError

func HandleInternalError(c echo.Context, err error, message string) error

HandleInternalError handles unexpected internal server errors

func HandleNotFoundError

func HandleNotFoundError(c echo.Context, resource string) error

HandleNotFoundError handles resource not found errors

func HandleUnauthorizedError

func HandleUnauthorizedError(c echo.Context, message string) error

HandleUnauthorizedError handles authentication failures

func HandleUnprocessableEntityError

func HandleUnprocessableEntityError(c echo.Context, message string) error

HandleUnprocessableEntityError handles business logic validation errors

func HandleValidationError

func HandleValidationError(c echo.Context, err error) error

HandleValidationError handles validation errors with detailed field-level information

Types

type ChannelRegistrationErrorHandler added in v0.4.0

type ChannelRegistrationErrorHandler struct{}

ChannelRegistrationErrorHandler provides specialized error handling for channel registration operations

func NewChannelRegistrationErrorHandler added in v0.4.0

func NewChannelRegistrationErrorHandler() *ChannelRegistrationErrorHandler

NewChannelRegistrationErrorHandler creates a new channel registration error handler

func (*ChannelRegistrationErrorHandler) GetErrorCategory added in v0.4.0

func (h *ChannelRegistrationErrorHandler) GetErrorCategory(errorCode string) string

GetErrorCategory categorizes errors for better error handling and monitoring

func (*ChannelRegistrationErrorHandler) GetUserFriendlyMessage added in v0.4.0

func (h *ChannelRegistrationErrorHandler) GetUserFriendlyMessage(errorCode string) string

GetUserFriendlyMessage provides user-friendly error messages for common error scenarios

func (*ChannelRegistrationErrorHandler) HandleBusinessRuleError added in v0.4.0

func (h *ChannelRegistrationErrorHandler) HandleBusinessRuleError(c echo.Context, err error) error

HandleBusinessRuleError handles business rule validation errors with proper HTTP status mapping

func (*ChannelRegistrationErrorHandler) HandleValidationError added in v0.4.0

func (h *ChannelRegistrationErrorHandler) HandleValidationError(c echo.Context, err error) error

HandleValidationError handles channel registration validation errors with proper HTTP status mapping

func (*ChannelRegistrationErrorHandler) IsRetryableError added in v0.4.0

func (h *ChannelRegistrationErrorHandler) IsRetryableError(errorCode string) bool

IsRetryableError determines if an error condition might be resolved by retrying

type ErrorResponse

type ErrorResponse struct {
	Error struct {
		Code    string      `json:"code"`              // Error code constant
		Message string      `json:"message"`           // Human-readable message
		Details interface{} `json:"details,omitempty"` // Additional error details (validation errors, etc.)
	} `json:"error"`
	Status string `json:"status"` // Always "error"
}

ErrorResponse represents a structured error response

func NewErrorResponse

func NewErrorResponse(code, message string, details interface{}) ErrorResponse

NewErrorResponse creates a new error response with the specified code, message, and details

type ManagerChangeErrorHandler added in v0.4.1

type ManagerChangeErrorHandler struct{}

ManagerChangeErrorHandler provides specialized error handling for manager change operations

func NewManagerChangeErrorHandler added in v0.4.1

func NewManagerChangeErrorHandler() *ManagerChangeErrorHandler

NewManagerChangeErrorHandler creates a new manager change error handler

func (*ManagerChangeErrorHandler) GetErrorCategory added in v0.4.1

func (h *ManagerChangeErrorHandler) GetErrorCategory(errorCode string) string

GetErrorCategory categorizes errors for better error handling and monitoring

func (*ManagerChangeErrorHandler) HandleBusinessRuleError added in v0.4.1

func (h *ManagerChangeErrorHandler) HandleBusinessRuleError(c echo.Context, err error) error

HandleBusinessRuleError handles manager change business rule validation errors with proper HTTP status mapping

func (*ManagerChangeErrorHandler) IsRetryableError added in v0.4.1

func (h *ManagerChangeErrorHandler) IsRetryableError(errorCode string) bool

IsRetryableError determines if an error condition might be resolved by retrying

type SuccessResponse

type SuccessResponse struct {
	Data   interface{} `json:"data"`   // Response data
	Status string      `json:"status"` // Always "success"
}

SuccessResponse represents a structured success response

func NewSuccessResponse

func NewSuccessResponse(data interface{}) SuccessResponse

NewSuccessResponse creates a new success response with the specified data

type ValidationError added in v0.4.0

type ValidationError interface {
	Error() string
	GetCode() string
	GetMessage() string
	GetDetails() interface{}
}

ValidationError interface for validation errors that can be handled by the channel error handler

Jump to

Keyboard shortcuts

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