Documentation
¶
Overview ¶
Package errors is brainjar's single domain-error type. Every app and handler returns either a wrapped *Error or *RefError; HTTP and CLI layers each map the Code to their own surface (status code, exit code, user message).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromHTTP ¶
FromHTTP decodes a brainjar error envelope from a non-2xx HTTP response. Returns *RefError when the envelope carries invalid_refs, otherwise *Error. Unknown envelope codes map to CodeUnknown. Non-JSON or missing envelopes fall back to deriving a code from the HTTP status.
Consumes resp.Body — callers should not read it afterward.
func FromJSON ¶
FromJSON parses a brainjar error envelope. Returns *RefError when invalid_refs is present, *Error otherwise. Non-envelope bytes become CodeUnknown carrying the raw text so callers still see something.
func IsConflict ¶
IsConflict reports whether err (or any error wrapped by it) is an Error with CodeConflict.
func IsNotFound ¶
IsNotFound reports whether err (or any error wrapped by it) is an Error with CodeNotFound.
func IsUnauthorized ¶
IsUnauthorized reports whether err (or any error wrapped by it) is an Error with CodeUnauthorized.
func ToHTTP ¶
func ToHTTP(err error, w http.ResponseWriter)
ToHTTP writes a structured JSON error response. Handlers call this in their error paths — no error-handling middleware needed.
Types ¶
type Code ¶
type Code int
Code is an enum of domain error codes. Maps to HTTP status codes for the server, and to exit codes / user messages for the CLI.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is the single error type for all domain errors. Handlers use ToHTTP() to convert it; CLI commands inspect Code() for UX.
func Conflict ¶
Conflict builds a CodeConflict error for a resource that already exists under the given identifier.
func (*Error) Error ¶
Error implements the error interface. Returns the raw message only; callers that want structure go through Code() and Hint().
func (*Error) HTTPStatus ¶
HTTPStatus returns the HTTP status code associated with e's Code. Unknown codes map to 500 so the server never returns a naked zero.