Documentation
¶
Overview ¶
Package errors provides HTTP error handling utilities for the API.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorHandler ¶
func ErrorHandler(fn HandlerWithError) http.HandlerFunc
ErrorHandler wraps a HandlerWithError and converts returned errors into appropriate HTTP responses.
The decorator:
- Returns early if no error is returned (handler already wrote response)
- Extracts HTTP status code from the error using errors.Code()
- For 5xx errors: logs full error details, returns generic message to client
- For 4xx errors: returns error message to client
Usage:
r.Get("/{name}", apierrors.ErrorHandler(routes.getWorkload))
Types ¶
type HandlerWithError ¶
type HandlerWithError func(http.ResponseWriter, *http.Request) error
HandlerWithError is an HTTP handler that can return an error. This signature allows handlers to return errors instead of manually writing error responses, enabling centralized error handling.
Click to show internal directories.
Click to hide internal directories.