Documentation
¶
Overview ¶
Package apierror holds the SDK's error model: the wire-error mapping and the typed error hierarchy returned to callers. It is re-exported by the bird package (bird.APIError, bird.RateLimitError, …), so these names are the semver-locked public surface.
Index ¶
- func FromResponse(status int, body []byte, header http.Header) error
- func ParseRetryAfter(header http.Header) (time.Duration, bool)
- type APIError
- type ConnectionError
- type ErrorDetail
- type ErrorNextAction
- type ErrorType
- type RateLimitError
- type TimeoutError
- type UnmetGate
- type ValidationError
- type WebhookVerificationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromResponse ¶
FromResponse turns a terminal non-2xx response into a typed error. It is the single place a wire error becomes a Go error. The API wraps errors as {"error": {...}}; a bare top-level body and a non-JSON body are both tolerated.
Types ¶
type APIError ¶
type APIError struct {
StatusCode int
Type ErrorType
// Code is the stable, opaque error code (E#####).
Code string
// Name is a human-readable slug for logs; paired with Code, never replaces it.
Name string
// Message is the human-readable description.
Message string
// DocURL links to the documentation for this Code.
DocURL string
// RequestID correlates with the X-Request-Id response header.
RequestID string
// Param is the offending field, when applicable.
Param string
// VendorCode is a verbatim code from a downstream system (SMTP reply, decline).
VendorCode string
// Remediation is a human-readable next step to resolve this error, when a
// recovery is known (ADR-0073).
Remediation string
// Next lists the operations that resolve this error, in the order to try them.
Next []ErrorNextAction
// UnmetGates lists the verification requirements blocking this action, each
// with the flow that resolves it. Present only when an action is blocked
// pending verification.
UnmetGates []UnmetGate
}
APIError is the error the server returned. It is the base for every API failure; catch it with errors.As to handle any server error uniformly.
type ConnectionError ¶
type ConnectionError struct{ Err error }
ConnectionError is a network-level failure with no HTTP response (DNS, connection refused, socket hangup).
func (*ConnectionError) Error ¶
func (e *ConnectionError) Error() string
func (*ConnectionError) Unwrap ¶
func (e *ConnectionError) Unwrap() error
type ErrorDetail ¶
type ErrorDetail struct {
// Param is the dotted field path, e.g. "to[0]", "subject".
Param string `json:"param"`
// Message is what is wrong with this field.
Message string `json:"message"`
}
ErrorDetail is one per-field validation failure.
type ErrorNextAction ¶ added in v0.2.2
type ErrorNextAction struct {
// Operation is the operationId of the follow-up operation that resolves this error.
Operation string `json:"operation"`
// Description is a short human-readable label for the recovery step.
Description string `json:"description,omitempty"`
// Scope is the permission scope the recovery operation requires, when it is scoped.
Scope string `json:"scope,omitempty"`
}
ErrorNextAction is one recovery operation the server suggests (ADR-0073): call it to resolve the error, then retry the original request.
type ErrorType ¶
type ErrorType string
ErrorType is the coarse error category clients branch on (ADR-0016). Branch on APIError.Type for the flat categories, or use errors.As for the variants that carry extra data (RateLimitError, ValidationError).
const ( ErrorTypeBadRequest ErrorType = "bad_request_error" ErrorTypeAuth ErrorType = "auth_error" ErrorTypeBilling ErrorType = "billing_error" ErrorTypePermission ErrorType = "permission_error" ErrorTypeNotFound ErrorType = "not_found_error" ErrorTypeConflict ErrorType = "conflict_error" ErrorTypePrecondition ErrorType = "precondition_error" ErrorTypePayloadTooLarge ErrorType = "payload_too_large_error" ErrorTypeMisdirected ErrorType = "misdirected_error" ErrorTypeValidation ErrorType = "validation_error" ErrorTypeRateLimit ErrorType = "rate_limit_error" ErrorTypeInternal ErrorType = "internal_error" ErrorTypeNotImplemented ErrorType = "not_implemented_error" )
type RateLimitError ¶
RateLimitError is a 429. RetryAfter is the server-advised wait, or zero when none was advised.
func (*RateLimitError) Unwrap ¶
func (e *RateLimitError) Unwrap() error
type TimeoutError ¶
TimeoutError means a single attempt exceeded its per-attempt timeout.
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
type UnmetGate ¶ added in v0.4.1
type UnmetGate struct {
// Slug is the stable identifier for the verification requirement.
Slug string `json:"slug"`
// Name is the human-readable name of the verification requirement.
Name string `json:"name"`
// Status is the requirement's current state.
Status string `json:"status"`
// RemediationKind is how to resolve this requirement.
RemediationKind string `json:"remediation_kind"`
}
UnmetGate is one verification requirement blocking the action, with the flow that resolves it. Present on APIError.UnmetGates when an action is blocked pending verification.
type ValidationError ¶
type ValidationError struct {
*APIError
Details []ErrorDetail
}
ValidationError is a 422; Details carries the per-field failures.
func (*ValidationError) Unwrap ¶
func (e *ValidationError) Unwrap() error
type WebhookVerificationError ¶
type WebhookVerificationError struct{ Reason string }
WebhookVerificationError means a webhook payload failed signature verification (bad signature, stale timestamp, malformed headers).
func (*WebhookVerificationError) Error ¶
func (e *WebhookVerificationError) Error() string