Documentation
¶
Overview ¶
Package errors defines the CodatError type returned by all SDK operations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CodatError ¶
type CodatError struct {
// Type classifies the error for programmatic handling.
Type ErrorType
// Message is a human-readable description.
Message string
// StatusCode is the HTTP status code, or 0 for network errors.
StatusCode int
// CorrelationID is the Codat-provided correlation identifier, if present.
CorrelationID string
// RetryAfter is the server-mandated retry delay for 429 responses.
RetryAfter float64 // seconds
// RawBody is the unparsed response body when JSON decoding fails.
RawBody string
// Cause is the underlying error, if any.
Cause error
}
CodatError is the single error type returned by all SDK operations. Inspect the Type field to distinguish between transient and permanent errors.
if err != nil {
var ce *codaterrors.CodatError
if errors.As(err, &ce) && ce.Type == codaterrors.ErrNotFound {
// handle 404
}
}
func NewErrorFromResponse ¶
func NewErrorFromResponse(statusCode int, body *RawErrorBody, retryAfterHeader string) *CodatError
NewErrorFromResponse constructs a CodatError from an HTTP response.
func (*CodatError) Error ¶
func (e *CodatError) Error() string
Error implements the error interface.
func (*CodatError) Retryable ¶
func (e *CodatError) Retryable() bool
Retryable returns true if the error is transient and should be retried.
func (*CodatError) Unwrap ¶
func (e *CodatError) Unwrap() error
Unwrap returns the underlying error for errors.Is / errors.As chaining.
type ErrorType ¶
type ErrorType string
ErrorType classifies a CodatError so callers can handle specific failure modes without string matching on the message.
const ( ErrUnauthorized ErrorType = "unauthorized" // ErrPaymentRequired indicates a 402 response: subscription or billing issue. ErrPaymentRequired ErrorType = "payment_required" // ErrForbidden indicates a 403 response: insufficient permissions. ErrForbidden ErrorType = "forbidden" // ErrNotFound indicates a 404 response: the requested resource does not exist. ErrNotFound ErrorType = "not_found" // ErrConflict indicates a 409 response: a resource conflict occurred. ErrConflict ErrorType = "conflict" // ErrRateLimited indicates a 429 response: the request rate limit was exceeded. ErrRateLimited ErrorType = "rate_limited" // ErrBadRequest indicates a 400 response: the request body is invalid. ErrBadRequest ErrorType = "bad_request" // ErrUnprocessable indicates a 422 response: the entity could not be processed. ErrUnprocessable ErrorType = "unprocessable" // ErrServerError indicates a 5xx response: a transient server-side error. ErrServerError ErrorType = "server_error" ErrServiceUnavailable ErrorType = "service_unavailable" // ErrNetwork indicates a transport-level failure (DNS, TLS, connection refused). ErrNetwork ErrorType = "network_error" // ErrTimeout indicates the request exceeded its deadline. ErrTimeout ErrorType = "timeout" // ErrAborted indicates the request context was canceled. ErrAborted ErrorType = "abort" // ErrJSONDecode indicates the response body could not be decoded as JSON. ErrJSONDecode ErrorType = "json_decode_error" // ErrUnknown indicates an error that could not be classified. ErrUnknown ErrorType = "unknown" )
func ErrorTypeFromStatus ¶
ErrorTypeFromStatus maps an HTTP status code to an ErrorType.
type RawErrorBody ¶
type RawErrorBody struct {
Message string `json:"message"`
Error string `json:"error"`
StatusMessage string `json:"statusMessage"`
CorrelationID string `json:"correlationId"`
CorrelationIDSnake string `json:"correlation_id"`
}
RawErrorBody is the JSON shape of a Codat error response.