Documentation
¶
Overview ¶
Package errors provides consistent error handling and response formatting for the API
Index ¶
- Constants
- func HandleBadRequestError(c echo.Context, message string) error
- func HandleConflictError(c echo.Context, message string) error
- func HandleDatabaseError(c echo.Context, err error) error
- func HandleForbiddenError(c echo.Context, message string) error
- func HandleInternalError(c echo.Context, err error, message string) error
- func HandleNotFoundError(c echo.Context, resource string) error
- func HandleUnauthorizedError(c echo.Context, message string) error
- func HandleUnprocessableEntityError(c echo.Context, message string) error
- func HandleValidationError(c echo.Context, err error) error
- type ErrorResponse
- type SuccessResponse
Constants ¶
const ( ErrCodeValidation = "VALIDATION_ERROR" ErrCodeDatabase = "DATABASE_ERROR" ErrCodeForbidden = "FORBIDDEN" ErrCodeNotFound = "NOT_FOUND" ErrCodeConflict = "CONFLICT" ErrCodeInternal = "INTERNAL_ERROR" ErrCodeBadRequest = "BAD_REQUEST" ErrCodeUnprocessable = "UNPROCESSABLE_ENTITY" ErrCodeTooManyRequests = "TOO_MANY_REQUESTS" )
Error codes for consistent error identification
Variables ¶
This section is empty.
Functions ¶
func HandleBadRequestError ¶
HandleBadRequestError handles malformed request errors
func HandleConflictError ¶
HandleConflictError handles resource conflict errors
func HandleDatabaseError ¶
HandleDatabaseError handles database errors by logging details but returning generic message
func HandleForbiddenError ¶
HandleForbiddenError handles authorization failures (user is authenticated but lacks permission)
func HandleInternalError ¶
HandleInternalError handles unexpected internal server errors
func HandleNotFoundError ¶
HandleNotFoundError handles resource not found errors
func HandleUnauthorizedError ¶
HandleUnauthorizedError handles authentication failures
func HandleUnprocessableEntityError ¶
HandleUnprocessableEntityError handles business logic validation errors
func HandleValidationError ¶
HandleValidationError handles validation errors with detailed field-level information
Types ¶
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 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