api

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: Apache-2.0 Imports: 3 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJSON

func DecodeJSON[T any](r Response) (T, error)

DecodeJSON tries to unmarshal the Response.Data of the given Response r into an object of T.

func DecodeJSONObjects

func DecodeJSONObjects[T any](r ListResponse) ([]T, error)

DecodeJSONObjects unmarshalls the Objects contained in the given ListResponse into a slice of T. To decode the full JSON response contained in ListResponse use Response.DecodeJSON.

Types

type APIError

type APIError struct {
	StatusCode int              `json:"statusCode"` // StatusCode is the HTTP response status code returned by the API.
	Body       []byte           `json:"body"`       // Body is the HTTP payload returned by the API.
	Request    rest.RequestInfo `json:"request"`    // Request is information about the original request that led to this response error.
}

APIError represents an error returned by an API with associated information.

func (APIError) Error

func (r APIError) Error() string

Error returns a string representation of the APIError, providing details about the failed API request. It includes the HTTP method, URL, status code, and response body.

Returns: - string: A string representing the error message.

type ListResponse

type ListResponse struct {
	Response
	Objects [][]byte `json:"-"`
}

ListResponse represents a multi-object API response It contains both the full JSON Data, and a slice of Objects for more convenient access

type Response

type Response struct {
	StatusCode int              `json:"-"`
	Data       []byte           `json:"-"`
	Request    rest.RequestInfo `json:"-"`
}

Response represents an API response

func (Response) AsAPIError

func (r Response) AsAPIError() (APIError, bool)

AsAPIError converts a Response object to an APIError if it represents a 4xx or 5xx error. If the Response does not represent an error, it returns an empty APIError and false.

Parameters: - r (Response): The Response object to convert to an APIError.

Returns:

  • (APIError, bool): An APIError containing error information and a boolean indicating whether the conversion was successful (true for errors, false otherwise).

func (Response) Is4xxError

func (r Response) Is4xxError() bool

Is4xxError returns true if the response indicates a 4xx client error HTTP status code. A status code between 400 and 499 (inclusive) is considered a client error.

func (Response) Is5xxError

func (r Response) Is5xxError() bool

Is5xxError returns true if the response indicates a 5xx server error HTTP status code. A status code between 500 and 599 (inclusive) is considered a server error.

func (Response) IsSuccess

func (r Response) IsSuccess() bool

IsSuccess returns true if the response indicates a successful HTTP status code. A status code between 200 and 299 (inclusive) is considered a success.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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