response

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package response provides the response handling logic for responses and any errors returned by the Paddle API.

Index

Constants

This section is empty.

Variables

View Source
var ErrErrorHandlerCallExpected = errors.New("error handler should be called, this response should not be handled here")

ErrErrorHandlerCallExpected should never be returned, it indicates that the error handling logic has failed.

View Source
var ErrUnexpectedResponse = errors.New("found nil paddle.Error when one was expected")

ErrUnexpectedResponse is returned when an paddle.Error was expected, but instead received nil.

Functions

func Handle

func Handle(req *http.Request, res *http.Response, dst any) (err error)

Handle handles the response from the Paddle API. The dst field is a response which will be decoded from the response body. The dst field should be given as a pointer. If the dst field is nil, no response body will be decoded. It is expected that any error handling logic is done before calling this function, and that this is only for handling of successful responses.

func HandleError

func HandleError(req *http.Request, res *http.Response, requestErr error) error

HandleError handles the error response from the Paddle API. This will handle cases where the response is the standard error response type from the API, and will return the decoded paddleerr.Error. If the response is not valid, a response.Error will be returned.

Types

type Error

type Error struct {
	Method string
	Path   string

	StatusCode   int
	ResponseBody []byte
	// contains filtered or unexported fields
}

Error contains the details of a non-expected error when making a request to the Paddle API. This is not to be confused with the public `paddleerr.Error` type. These are returned in cases of non-expected errors, such as decoding, timeouts, malformed response bodies, etc. The cause of the error can be inspected using errors.Is.

func NewError

func NewError(cause error, method, path string, statusCode int, body []byte) *Error

NewError returns an instance of *Error, which conforms to the error interface and allows Unwrap.

func (*Error) Error

func (de *Error) Error() string

Error conforms to the errors interface.

func (*Error) Unwrap

func (de *Error) Unwrap() error

Unwrap allows errors.Is on the underlying error to be performed.

type Meta

type Meta struct {
	RequestID  string      `json:"request_id"`
	Pagination *Pagination `json:"pagination"`
}

Meta represents the metadata returned by the Paddle API.

type Pagination

type Pagination struct {
	PerPage        int    `json:"per_page"`
	Next           string `json:"next"`
	HasMore        bool   `json:"has_more"`
	EstimatedTotal int    `json:"estimated_total"`
}

Pagination represents the pagination information returned by the Paddle API.

type Response

type Response[T any] struct {
	Data  T                `json:"data"`
	Error *paddleerr.Error `json:"error"`
	Meta  Meta             `json:"meta"`
}

Response is the wrapper response type returned by the Paddle API.

Jump to

Keyboard shortcuts

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