apierr

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package apierr provides structured error types for tier0 CLI API calls. When the backend returns a non-2xx HTTP status, the CLI wraps it in an APIError and attaches a human-readable hint so AI agents and users know exactly what to do next.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	// HTTPStatus is the HTTP status code (401, 403, 404 …).
	HTTPStatus int
	// Code is the backend ResultVO code (may differ from HTTPStatus).
	Code int `json:"code,omitempty"`
	// Message is the human-readable error message from the backend.
	Message string
	// Hint is the suggested next action for the caller / AI agent.
	Hint string
	// HintCommand is a ready-to-run CLI command that fixes the problem, if applicable.
	HintCommand string
}

APIError is a structured error returned by the backend API.

func New

func New(httpStatus int, rawBody string) *APIError

New builds an APIError from an HTTP status code and the raw response body, automatically attaching an appropriate hint.

func NewBusiness added in v0.6.5

func NewBusiness(code int, rawBody string) *APIError

NewBusiness builds an APIError from a Tier0 business-envelope code. Business codes are not HTTP status codes and must never become retryable merely because their numeric value is greater than 500.

func (*APIError) Category added in v0.5.0

func (e *APIError) Category() errs.Category

Category returns the errs.Category corresponding to the HTTP status code. This is used by the central error dispatcher to select the exit code and the JSON "type" field.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Format

func (e *APIError) Format() string

Format returns the JSON representation of the error (unified envelope). Kept for backward compatibility; prefer ToEnvelope().Format().

func (*APIError) ToEnvelope added in v0.5.0

func (e *APIError) ToEnvelope() errs.Envelope

ToEnvelope converts an APIError into the unified errs.Envelope for JSON output.

Jump to

Keyboard shortcuts

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