Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrBadRequest = New(http.StatusBadRequest, "bad_request", "bad request") ErrForbidden = New(http.StatusForbidden, "forbidden", "forbidden") ErrNotFound = New(http.StatusNotFound, "not_found", "not found") ErrConflict = New(http.StatusConflict, "conflict", "conflict") ErrValidation = New(http.StatusUnprocessableEntity, "validation_failed", "validation failed") ErrTooManyRequests = New(http.StatusTooManyRequests, "too_many_requests", "too many requests") ErrInternal = New(http.StatusInternalServerError, "internal_error", "internal server error") )
Functions ¶
func Render ¶
func Render(w http.ResponseWriter, r *http.Request, err error, cfg RenderConfig)
Render writes an error response to the writer, negotiating content type based on the Accept header. In dev mode, stack traces are included.
Types ¶
type Error ¶
type Error struct {
Status int `json:"status"`
Code string `json:"code"`
Message string `json:"message"`
Details map[string]any `json:"details,omitempty"`
// contains filtered or unexported fields
}
Error represents a structured, typed error with an HTTP status code, machine-readable code, human-readable message, and optional details.
func (*Error) WithCause ¶
WithCause returns a new Error wrapping the given cause. The original error is not modified.
func (*Error) WithDetails ¶
WithDetails returns a new Error with the given details map. The original error is not modified.
func (*Error) WithMessage ¶
WithMessage returns a new Error with a different message. The original error is not modified.
type RenderConfig ¶
type RenderConfig struct {
IsDev bool
}
RenderConfig configures how errors are rendered in HTTP responses.
Click to show internal directories.
Click to hide internal directories.