Documentation
¶
Index ¶
Constants ¶
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 ¶
ErrorTypeFromStatus maps an HTTP status code to a string error type.
func ExitCodeFromStatus ¶
ExitCodeFromStatus maps an HTTP status code to a structured exit code.
func HintFromStatus ¶
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,omitempty"`
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 ¶
NewFromHTTP constructs an APIError from an HTTP response status, body text, the originating request method and path, and the HTTP response (for header parsing). The resp parameter may be nil.
func (*APIError) WriteStderr ¶
func (e *APIError) WriteStderr()
WriteStderr writes the JSON-encoded error to os.Stderr.
type AlreadyWrittenError ¶ added in v0.8.1
type AlreadyWrittenError struct{ Code int }
AlreadyWrittenError is a sentinel error indicating that the JSON error has already been written to stderr, so the caller should not write a second one. The Code field holds the process exit code.
func (*AlreadyWrittenError) Error ¶ added in v0.8.1
func (e *AlreadyWrittenError) Error() string
type RequestInfo ¶
RequestInfo holds metadata about the HTTP request that triggered the error.