Documentation
¶
Index ¶
- Constants
- func WriteErrorResponse(c *gin.Context, statusCode int, err error)
- func WriteErrorResponseWithDetails(c *gin.Context, statusCode int, err error, details interface{})
- func WriteHTTPError(w http.ResponseWriter, r *http.Request, statusCode int, err error)
- func WriteHTTPErrorWithDetails(w http.ResponseWriter, r *http.Request, statusCode int, err error, ...)
- type ErrorResponse
Constants ¶
View Source
const ( // ErrCodeBadRequest represents a bad request error (400) ErrCodeBadRequest = http.StatusBadRequest 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 = http.StatusServiceUnavailable )
Error codes constants
Variables ¶
This section is empty.
Functions ¶
func WriteErrorResponse ¶
WriteErrorResponse writes a standardized error response to the Gin context
func WriteErrorResponseWithDetails ¶
WriteErrorResponseWithDetails writes a standardized error response with additional details
func WriteHTTPError ¶
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
Click to show internal directories.
Click to hide internal directories.