errors

package
v0.0.0-...-7729239 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrCodeBadRequest represents a bad request error (400)
	ErrCodeBadRequest = http.StatusBadRequest

	// ErrCodeUnauthorized represents an unauthorized error (401)
	ErrCodeUnauthorized = http.StatusUnauthorized

	// ErrCodeForbidden represents a forbidden error (403)
	ErrCodeForbidden = http.StatusForbidden

	// ErrCodeNotFound represents a not found error (404)
	ErrCodeNotFound = http.StatusNotFound

	// ErrCodeRequestTimeout represents a request timeout error (408)
	ErrCodeRequestTimeout = http.StatusRequestTimeout

	// ErrCodeRequestEntityTooLarge represents a request entity too large error (413)
	ErrCodeRequestEntityTooLarge = http.StatusRequestEntityTooLarge

	// ErrCodeTooManyRequests represents a too many requests error (429)
	ErrCodeTooManyRequests = http.StatusTooManyRequests

	// ErrCodeInternalServerError represents an internal server error (500)
	ErrCodeInternalServerError = http.StatusInternalServerError

	// ErrCodeServiceUnavailable represents a service unavailable error (503)
	ErrCodeServiceUnavailable = http.StatusServiceUnavailable
)

Error codes constants

Variables

This section is empty.

Functions

func WriteErrorResponse

func WriteErrorResponse(c *gin.Context, statusCode int, err error)

WriteErrorResponse writes a standardized error response to the Gin context

func WriteErrorResponseWithDetails

func WriteErrorResponseWithDetails(c *gin.Context, statusCode int, err error, details interface{})

WriteErrorResponseWithDetails writes a standardized error response with additional details

func WriteHTTPError

func WriteHTTPError(w http.ResponseWriter, r *http.Request, statusCode int, err error)

WriteHTTPError writes a standardized error response to http.ResponseWriter

func WriteHTTPErrorWithDetails

func WriteHTTPErrorWithDetails(w http.ResponseWriter, r *http.Request, statusCode int, err error, details interface{})

WriteHTTPErrorWithDetails writes a standardized error response with additional details

Types

type ErrorResponse

type ErrorResponse struct {
	// Code is the HTTP status code
	Code int `json:"code"`

	// Message is the error message
	Message string `json:"message"`

	// TraceID is the trace ID for request tracking (optional)
	TraceID string `json:"trace_id,omitempty"`

	// RequestID is the request ID for internal tracking (optional)
	RequestID string `json:"request_id,omitempty"`

	// Details contains additional error details (optional)
	Details interface{} `json:"details,omitempty"`
}

ErrorResponse represents a standardized error response format

Jump to

Keyboard shortcuts

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