httperror

package
v0.0.0-...-2102962 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 3 Imported by: 2

README

Package cloudeng.io/net/http/httperror

import cloudeng.io/net/http/httperror

Functions

Func CheckResponse
func CheckResponse(err error, resp *http.Response) error

CheckResponse creates a new instance of T given an error and http.Response returned by an http request operation (e.g. Get, Do etc). If err is nil, resp must not be nil. It will return nil if err is nil and resp.StatusCode is http.StatusOK. Otherwise, it will create an instance of httperror.T with the appropriate fields set.

Func CheckResponseRetries
func CheckResponseRetries(err error, resp *http.Response, retries int) error

CheckResponseRetries is like Checkresponse but will set the retries field.

Func IsHTTPError
func IsHTTPError(err error, httpStatusCode int) bool

IsHTTPError returns true if err contains the specified http status code.

Types

Type T
type T struct {
	Err        error
	Status     string
	StatusCode int
	Retries    int
}

T represents an error encountered while making an HTTP request of some form. The error may be the result of a failed local operation (in which case Err will be non-nil), or an error returned by the remote server (in which case Err will be nil but StatusCode will something other than http.StatusOK). In all cases, Err or StatusCode must contain an error.

Functions
func AsT(httpStatusCode int) *T

AsT returns an httperror.T for the specified http status code.

Methods
func (err *T) Error() string

Error implements error.

func (err *T) Is(target error) bool

Is implements errors.Is.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(err error, resp *http.Response) error

CheckResponse creates a new instance of T given an error and http.Response returned by an http request operation (e.g. Get, Do etc). If err is nil, resp must not be nil. It will return nil if err is nil and resp.StatusCode is http.StatusOK. Otherwise, it will create an instance of httperror.T with the appropriate fields set.

func CheckResponseRetries

func CheckResponseRetries(err error, resp *http.Response, retries int) error

CheckResponseRetries is like Checkresponse but will set the retries field.

func IsHTTPError

func IsHTTPError(err error, httpStatusCode int) bool

IsHTTPError returns true if err contains the specified http status code.

Types

type T

type T struct {
	Err        error
	Status     string
	StatusCode int
	Retries    int
}

T represents an error encountered while making an HTTP request of some form. The error may be the result of a failed local operation (in which case Err will be non-nil), or an error returned by the remote server (in which case Err will be nil but StatusCode will something other than http.StatusOK). In all cases, Err or StatusCode must contain an error.

func AsT

func AsT(httpStatusCode int) *T

AsT returns an httperror.T for the specified http status code.

func (*T) Error

func (err *T) Error() string

Error implements error.

func (*T) Is

func (err *T) Is(target error) bool

Is implements errors.Is.

Jump to

Keyboard shortcuts

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