errors

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 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"
)

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

Jump to

Keyboard shortcuts

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