Documentation
¶
Overview ¶
Package errors defines portable application error primitives and the problem document model used at HTTP transport boundaries.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Code ¶
type Code string
Code identifies an application-level error class.
func CodeOf ¶
Code extracts the platform error code from an error. Returns CodeInternal if the error is not a platform error.
func (Code) HTTPStatus ¶
HTTPStatus maps a Code to its canonical HTTP status code.
type Error ¶
Error is the platform error model.
func Wrap ¶
Wrap wraps an existing error under a platform error code. The original error is preserved for logging and tracing.
func (*Error) StatusCode ¶
StatusCode implements the httpx ErrorEncoder status-code interface. It returns the canonical HTTP status for the error code, allowing httpx.DefaultErrorEncoder to map platform errors to correct HTTP statuses without a direct import dependency from httpx → errors.
type Problem ¶
type Problem struct {
Type string `json:"type,omitempty"`
Title string `json:"title"`
Status int `json:"status"`
Code string `json:"code"`
Detail string `json:"detail,omitempty"`
Instance string `json:"instance,omitempty"`
RequestID string `json:"request_id,omitempty"`
TraceID string `json:"trace_id,omitempty"`
}
Problem is the application/problem+json response shape (RFC 7807).
func ToProblem ¶
ToProblem converts a platform error to a Problem document. Instance, RequestID, and TraceID should be set by the transport layer.
For server-side error codes (5xx), the Detail field is intentionally left empty to prevent internal implementation details from leaking to clients. Client-facing error codes (4xx) include the message in Detail since these are expected to contain safe, actionable information.