httpclient

package
v0.27.1-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MIMETypeJSON defines the MIME type for JSON documents.
	MIMETypeJSON = "application/json"
)

Variables

This section is empty.

Functions

func WrapURLError

func WrapURLError(err error) error

WrapURLError is a helper to add an end-user message to trasnport errros.

Resty doesn't provide a hook for errors in `http.Client.Do`, e.g. if the connector configuration contains an invalid URL. This wrapper offers clients a way to handle such cases:

if _, err := httpclient.New(name, host).R().Post(url); err != nil {
    return nil, httpclient.WrapURLError(err)
}

Types

type Client

type Client struct {
	*resty.Client
	// contains filtered or unexported fields
}

Client performs HTTP requests for connectors, implementing error handling and logging in a consistent way.

func New

func New(name, host string, options ...Option) *Client

New returns an httpclient configured to call a remote host.

type ErrBody

type ErrBody interface {
	Message() string
}

ErrBody allows Client to extract an error message from the API.

type Option

type Option func(*Client)

Option provides configuration options for a client.

func WithEndUserError

func WithEndUserError(e ErrBody) Option

WithEndUserError will unmarshal error response bodies as the error struct and will use their message as an end-user error.

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger will use the provider logger to log the request and response information.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL