1package typesafe23import (4 "fmt"5 "net/http"6)78// APIError describes a non-2xx HTTP response. Use errors.AsType to inspect it.9// Body and Header retain the server response and may contain sensitive data.10// Error deliberately excludes the body, credentials, and full URL.11type APIError struct {12 StatusCode int13 RequestID string14 Header http.Header15 Body []byte16 Method string17 URL string18 Message string19}2021// Error returns an HTTP status summary without exposing response body contents.22func (e *APIError) Error() string {23 return fmt.Sprintf("typesafe: %s returned HTTP %d %s", e.Method, e.StatusCode, e.Message)24}2526// ResponseError reports an invalid or oversized API response.27// RequestID can be used to correlate the failure with the API service.28type ResponseError struct {29 RequestID string30 Err error31}3233// Error returns a summary. Inspect Unwrap for the detailed decoding error.34func (e *ResponseError) Error() string {35 return "typesafe: invalid API response"36}3738// Unwrap exposes the underlying response decoding or validation error.39func (e *ResponseError) Unwrap() error { return e.Err }