Documentation
¶
Index ¶
- func Status(code Code) int
- func TraceID(ctx context.Context) string
- func Write(ctx context.Context, w http.ResponseWriter, status int, err *Error)
- func WriteError(ctx context.Context, w http.ResponseWriter, err *Error)
- type Code
- type Error
- func AlreadyExists(message string) *Error
- func As(err error) (*Error, bool)
- func Conflict(message string) *Error
- func DeadlineExceeded(message string) *Error
- func FailedPrecondition(message string) *Error
- func Forbidden(message string) *Error
- func Internal(message string) *Error
- func InvalidArgument(message string) *Error
- func New(code Code, message string, details map[string]any) *Error
- func NotFound(message string) *Error
- func ResourceExhausted(message string) *Error
- func Unauthenticated(message string) *Error
- func Unavailable(message string) *Error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TraceID ¶
TraceID returns trace_id from OpenTelemetry span context. If there's no valid span context, it returns empty string. NOTE: request_id is NOT a trace_id and must not be used as fallback.
func Write ¶
Write writes a JSON error response. It guarantees: - content-type is application/json; charset=utf-8 - details is always an object (never null) - trace_id is injected from OTel span context if missing
func WriteError ¶
func WriteError(ctx context.Context, w http.ResponseWriter, err *Error)
Types ¶
type Code ¶
type Code string
const ( // Generic CodeInternal Code = "INTERNAL" // Auth CodeUnauthenticated Code = "UNAUTHENTICATED" CodeForbidden Code = "FORBIDDEN" // Validation / client CodeInvalidArgument Code = "INVALID_ARGUMENT" CodeNotFound Code = "NOT_FOUND" CodeConflict Code = "CONFLICT" CodeTooManyRequests Code = "TOO_MANY_REQUESTS" CodeResourceExhausted Code = "RESOURCE_EXHAUSTED" // Optional (recommended for core/orders/payments) CodeDeadlineExceeded Code = "DEADLINE_EXCEEDED" CodeAlreadyExists Code = "ALREADY_EXISTS" CodeFailedPrecondition Code = "FAILED_PRECONDITION" )
type Error ¶
type Error struct {
Code Code `json:"code"`
Message string `json:"message"`
Details map[string]any `json:"details"`
TraceID string `json:"trace_id"`
}
func AlreadyExists ¶
func DeadlineExceeded ¶
func FailedPrecondition ¶
func InvalidArgument ¶
func ResourceExhausted ¶
func Unauthenticated ¶
func Unavailable ¶
func (*Error) MarshalJSON ¶
Click to show internal directories.
Click to hide internal directories.