errors

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitOK         = 0
	ExitError      = 1
	ExitAuth       = 2
	ExitNotFound   = 3
	ExitValidation = 4
	ExitRateLimit  = 5
	ExitConflict   = 6
	ExitServer     = 7
)

Exit code constants for structured error handling.

Variables

This section is empty.

Functions

func ErrorTypeFromStatus

func ErrorTypeFromStatus(status int) string

ErrorTypeFromStatus maps an HTTP status code to a string error type.

func ExitCodeFromStatus

func ExitCodeFromStatus(status int) int

ExitCodeFromStatus maps an HTTP status code to a structured exit code.

func HintFromStatus

func HintFromStatus(status int) string

HintFromStatus returns a helpful hint string for well-known error statuses. Returns an empty string for statuses that do not have a standard hint.

Types

type APIError

type APIError struct {
	ErrorType  string       `json:"error_type"`
	Status     int          `json:"status"`
	Message    string       `json:"message"`
	Hint       string       `json:"hint,omitempty"`
	Request    *RequestInfo `json:"request,omitempty"`
	RetryAfter *int         `json:"retry_after,omitempty"`
}

APIError is a structured error with an HTTP status, typed error category, human-readable message, optional hint, and optional request context.

func NewFromHTTP

func NewFromHTTP(status int, body string, method, path string) *APIError

NewFromHTTP constructs an APIError from an HTTP response status, body text, and the originating request method and path.

func (*APIError) Error

func (e *APIError) Error() string

Error implements the error interface.

func (*APIError) ExitCode

func (e *APIError) ExitCode() int

ExitCode returns the process exit code appropriate for this error.

func (*APIError) WriteJSON

func (e *APIError) WriteJSON(w io.Writer)

WriteJSON encodes the error as a JSON object and writes it to w.

func (*APIError) WriteStderr

func (e *APIError) WriteStderr()

WriteStderr writes the JSON-encoded error to os.Stderr.

type RequestInfo

type RequestInfo struct {
	Method string `json:"method"`
	Path   string `json:"path"`
}

RequestInfo holds metadata about the HTTP request that triggered the error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL