Documentation
¶
Overview ¶
Package errors defines errors that can be transported safely across service boundaries without exposing their internal causes.
Index ¶
Constants ¶
const ( CodeOK = 0 CodeInvalidArgument = 10001 CodeInternal = 90001 CodeTimeout = 90002 // CodeMax is the largest business code representable by JGO's standard // protobuf int32 response field. CodeMax = 1<<31 - 1 )
const ( MessageInternal = "internal server error" MessageTimeout = "request timeout" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Catalog ¶ added in v0.4.0
type Catalog struct {
// contains filtered or unexported fields
}
Catalog validates and resolves a finite set of business error codes.
func MergeCatalogs ¶ added in v0.4.0
MergeCatalogs builds one process catalog from service-local and shared catalogs. Duplicate codes or names across module/repository boundaries are rejected by the same rules as NewCatalog.
func MustCatalog ¶ added in v0.4.0
func MustCatalog(definitions ...Definition) *Catalog
func MustMergeCatalogs ¶ added in v0.4.0
func NewCatalog ¶ added in v0.4.0
func NewCatalog(definitions ...Definition) (*Catalog, error)
func (*Catalog) Definitions ¶ added in v0.4.0
func (c *Catalog) Definitions() []Definition
Definitions returns a stable copy suitable for governance tooling and composing catalogs supplied by shared Go modules.
func (*Catalog) FromCode ¶ added in v0.4.0
FromCode converts a downstream RPC business code into an HTTP-aware Error. Unknown codes preserve their public code/message but deliberately map to 500.
func (*Catalog) HTTPStatus ¶ added in v0.4.0
HTTPStatus returns 500 for unknown codes so unmapped downstream business failures never masquerade as a successful HTTP response.
func (*Catalog) LookupCode ¶ added in v0.4.0
func (c *Catalog) LookupCode(code int) (Definition, bool)
func (*Catalog) LookupName ¶ added in v0.4.0
func (c *Catalog) LookupName(name string) (Definition, bool)
type Definition ¶ added in v0.4.0
type Definition struct {
// contains filtered or unexported fields
}
Definition is one stable, transport-safe business error declaration.
func Define ¶ added in v0.4.0
func Define(code int, name, message string, httpStatus int) Definition
func (Definition) Code ¶ added in v0.4.0
func (d Definition) Code() int
func (Definition) HTTPStatus ¶ added in v0.4.0
func (d Definition) HTTPStatus() int
func (Definition) Message ¶ added in v0.4.0
func (d Definition) Message() string
func (Definition) Name ¶ added in v0.4.0
func (d Definition) Name() string
func (Definition) New ¶ added in v0.4.0
func (d Definition) New() *Error
func (Definition) Wrap ¶ added in v0.4.0
func (d Definition) Wrap(cause error) *Error
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is a public service error with an optional private cause.
func New ¶
New creates a service error. Invalid public fields are replaced by safe internal-error defaults.
func Wrap ¶
Wrap creates a service error while preserving an internal cause for logs and errors.Is/errors.As. The cause is never returned by MessageOf.
func (*Error) HTTPStatus ¶
HTTPStatus returns the HTTP status associated with the error.