Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // NoopTokenProvider is a token provider that returns an empty string which is ignored by `DoRequest`. NoopTokenProvider = TokenProvider(func() (token string, err error) { return "", nil }) )
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct { // Status is the HTTP status of the API response Status int // Header is the set of response headers Header http.Header // Response is the bytes of the response body Response []byte }
APIError describes an error during unsuccessful HTTP request to an API
func (APIError) Error ¶
Error implements the error interface. Builds a complete error message out of all the errors served in the API response. This should be used in logging, tracing, debugging, etc. For user facing errors use `ValidationErrors` function.
func (APIError) ResponseErrors ¶ added in v3.6.1
ResponseErrors returns a slice of all errors that were present in the API response. All the field errors are folded into a single validation error map. All the general errors are mapped to regular errors. Returns `nil` if the response contained no errors in the expected JSON format. For the 522 status code it handles a special case where all the general errors become validation errors for the `connection` field.
func (APIError) ValidationErrors ¶ added in v3.6.1
func (e APIError) ValidationErrors() (errs cerrors.ValidationErrors)
ValidationErrors returns a map of validation errors in case they were present in response errors. Otherwise, returns `nil` if there were no validation errors in the response.
type BaseAPIClient ¶
type BaseAPIClient interface { // GetBaseURL returns the base URL of the service which can be used in HTTP request tasks. GetBaseURL() string // DoRequest performs the HTTP request with the given parameters, marshals the payload and // unmarshals the response into the given output if the status code is successful DoRequest(ctx context.Context, method, path string, query url.Values, payload, out interface{}) error }
BaseAPIClient describes all basic HTTP client operations required to work with a JSON API
func NewBaseAPIClient ¶
func NewBaseAPIClient(basePath, tokenHeaderName string, tokenProvider TokenProvider, client *http.Client, debug bool) BaseAPIClient
NewBaseAPIClient creates a new instance of the base API client implementation. Never use `debug=true` in production environments, it will leak sensitive data
type TokenProvider ¶
TokenProvider is a function that gets the token string for each request
func TokenProviderFromCreator ¶
func TokenProviderFromCreator(tc tokens.Creator, reference string, opts tokens.Options) TokenProvider
TokenProviderFromCreator creates a token provider out of token creator.