restkit

package module
v0.0.0-...-7d9476f Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: Apache-2.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidConfig  = errors.New("rest: invalid config")
	ErrEmptyMethod    = errors.New("rest: empty method")
	ErrEmptyErrorBody = errors.New("rest: empty error body")
	ErrUnmarshalJSON  = errors.New("rest: failed to unmarshal body")
)

Functions

func IsAPIError

func IsAPIError(err error) bool

IsAPIError checks if an error is an API error with a response body

func IsClientError

func IsClientError(err error) bool

IsClientError reports whether err is a client (4xx) error. This function now works with the new error hierarchy while maintaining backward compatibility.

func IsInfrastructureError

func IsInfrastructureError(err error) bool

IsInfrastructureError checks if error is a network infrastructure error

func IsInternalError

func IsInternalError(err error) bool

IsInternalError checks if error is an internal library error

func IsServerError

func IsServerError(err error) bool

IsServerError reports whether err is a server (5xx) error. This function now works with the new error hierarchy while maintaining backward compatibility.

Types

type APIError

type APIError struct {
	StatusCode int    // HTTP status code
	URL        string // URL of the request
	Body       []byte // Raw error response body
}

APIError represents server responses with error status codes

func AsAPIError

func AsAPIError(err error) (*APIError, bool)

AsAPIError attempts to extract an APIError from an error chain

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) ParseError

func (e *APIError) ParseError(target any) error

ParseError attempts to parse the error body into the provided struct

func (*APIError) RawBody

func (e *APIError) RawBody() []byte

RawBody returns the raw error response body

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config Config) (*Client, error)

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, headers http.Header, payload, response any) error

func (*Client) DoRAW

func (c *Client) DoRAW(
	ctx context.Context,
	method, path string,
	headers http.Header,
	payload io.Reader,
	response any,
) error

type Config

type Config struct {
	Client  *http.Client // Optional HTTP Client, defaults to `http.DefaultClient`
	BaseURL string       // Optional base URL
}

type ErrorWithBody

type ErrorWithBody interface {
	RawBody() []byte             // RawBody returns the raw error response body
	ParseError(target any) error // ParseError attempts to parse the error body
}

ErrorWithBody provides access to raw error response bodies. ParseError expects target to be a pointer to a struct; it returns a json.Unmarshal error otherwise.

type InfrastructureError

type InfrastructureError struct {
	Err error
	URL string
}

InfrastructureError represents network-level failures

func (*InfrastructureError) Error

func (e *InfrastructureError) Error() string

func (*InfrastructureError) Unwrap

func (e *InfrastructureError) Unwrap() error

type InternalError

type InternalError struct {
	Err error  // Underlying error
	Op  string // Operation where error occurred
}

InternalError represents errors in request construction

func (*InternalError) Error

func (e *InternalError) Error() string

func (*InternalError) Unwrap

func (e *InternalError) Unwrap() error

Jump to

Keyboard shortcuts

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