httputil

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const HTTPStatusErrorBodyMaxLength = 64 * 1024

HTTPStatusErrorBodyMaxLength specifies the maximum length of HTTPStatusError.Body

Variables

This section is empty.

Functions

func NewHTTPClient

func NewHTTPClient(socketPath string) (*http.Client, error)

func Successful

func Successful(resp *http.Response) error

Successful returns an error if the status code is not 2xx.

func WriteError

func WriteError(w http.ResponseWriter, r *http.Request, err error, ec int)

WriteError writes an error. WriteError sould not be used if an error may contain sensitive information and the client is not reliable.

Types

type ErrorJSON

type ErrorJSON struct {
	Message string `json:"message"`
}

ErrorJSON is returned with "application/json" content type and non-2XX status code

type HTTPStatusError

type HTTPStatusError struct {
	// StatusCode is non-2XX status code
	StatusCode int
	// Body is at most HTTPStatusErrorBodyMaxLength
	Body string
}

HTTPStatusError is created from non-2XX HTTP response

func (*HTTPStatusError) Error

func (e *HTTPStatusError) Error() string

Error implements error. If e.Body is a marshalled string of api.ErrorJSON, Error returns ErrorJSON.Message . Otherwise Error returns a human-readable string that contains e.StatusCode and e.Body.

Jump to

Keyboard shortcuts

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