Documentation
¶
Index ¶
- Variables
- func DecodeLenient[T any](rsp *http.Response, err error, ia *cassette.Interaction, debugFile string, ...) error
- func NewErrBody(rsp *http.Response, body []byte) error
- func NewErrCustom(rsp *http.Response, err error) error
- func NewErrStatusCode(rsp *http.Response) error
- func NewErrUnknownContentType(rsp *http.Response) error
- func NewErrUnknownStatusCode(rsp *http.Response) error
- func WrapDecodingError(rsp *http.Response, err error) error
- type DecodingError
- type Error
- type ErrorBody
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknownStatusCode is returned when the response status code is not known, // i.e. it has not been defined in the OpenAPI specification. ErrUnknownStatusCode = errors.New("unknown status code") // ErrUnknownContentType is returned when the response content type is not known, // i.e. it has not been defined in the OpenAPI specification // for the status code of the response. ErrUnknownContentType = errors.New("unknown content type") // ErrStatusCode is returned when the status code indicates an error. ErrStatusCode = errors.New("status code indicates an error") )
Functions ¶
func DecodeLenient ¶
func DecodeLenient[T any](rsp *http.Response, err error, ia *cassette.Interaction, debugFile string, out *T, opts json.Options, ) error
DecodeLenient is a debug-capable client's second try at a response body it could not decode as opts say, err being why. Decoding it the first time is the client's own, so that a client not in debug mode does nothing more than decode.
In debug mode, ia is the call the client recorded: DecodeLenient adds it to the interactions in debugFile, for openapi-enrich to learn from, and decodes the body ia recorded into out again, with members the specification does not know allowed, so that the response is still of use while they wait to be added. Without debug mode, ia is nil, and it returns err as a decoding error.
func NewErrBody ¶
NewErrBody wraps an undecoded response body in an api.Error. Use this when the status code is unsuccessful and the API returns a body the specification gives no schema for, leaving nothing to decode it into.
func NewErrCustom ¶
NewErrCustom wraps a custom error in an api.Error. Use this if the status code is unsuccessful and the API returns more information, e.g. as part of a JSON that can be parsed and transformed into an error.
func NewErrStatusCode ¶
func NewErrUnknownStatusCode ¶
Types ¶
type DecodingError ¶
type DecodingError struct{ Err error }
DecodingError is an error returned when decoding the response body failed.
func (*DecodingError) Unwrap ¶
func (e *DecodingError) Unwrap() error
Unwrap returns the underlying error, e.g. a json.SemanticError.
type Error ¶
type Error struct {
// The HTTP response.
Response *http.Response
// The underlying error.
Err error
// Indicates that this is a custom error returned by the API.
IsCustom bool
}
Error is an error returned by the API client. Use errors.As to check if the underlying error is of a specific type.
func (Error) ContentType ¶
ContentType returns the HTTP content type.
func (Error) StatusCode ¶
StatusCode returns the HTTP status code of the response.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package apitest holds what the tests openapi-codegen generates need, as net/http/httptest holds what tests of HTTP need: servers that answer as told, the replay of recorded interactions, and the checks of what a client decoded and of a type's round trip.
|
Package apitest holds what the tests openapi-codegen generates need, as net/http/httptest holds what tests of HTTP need: servers that answer as told, the replay of recorded interactions, and the checks of what a client decoded and of a type's round trip. |
|
Package paging yields what an API lists a page at a time, fetching each page as the one before is used up.
|
Package paging yields what an API lists a page at a time, fetching each page as the one before is used up. |
|
Package union holds what the code openapi-codegen generates decodes and encodes unions and tagged structs with: JSON values of several alternatives, of which the code chooses one by a discriminator, by the members an alternative requires and declares, or by a tag.
|
Package union holds what the code openapi-codegen generates decodes and encodes unions and tagged structs with: JSON values of several alternatives, of which the code chooses one by a discriminator, by the members an alternative requires and declares, or by a tag. |