errhttp

package module
v0.0.0-...-271a6f5 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 2 Imported by: 1

README

go-errhttp

Package errhttp provides errors and types that make dealing with HTTP response errors easier, for the Go programming language.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/sourcecode.social/reiver/go-errhttp

GoDoc

Example

Here is an example of wrapping an error:

	import "sourcecode.social/reiver/go-errhttp"
	
	// ...
	
	if err := something(); nil != err {
		return errhttp.BadRequestWrap(err)
	}
	
	// ...
	
	switch err.(type) {
	case errhttp.BadRequest:
		//@TODO
	case errhttp.NotFound:
		//@TODO
	case errhttp.InternalServerError:
		//@TODO
		
	case errhttp.ClientError:
		//@TODO
	case errhttp.ServerError:
		//@TODO
		
	default:
		//@TODO
	}

Here is an example of using one of the package global variable errors:

	import "sourcecode.social/reiver/go-errhttp"
	
	// ...
	
	return errhttp.ErrBadRequest
	
	// ...
	
	switch err.(type) {
	case errhttp.BadRequest:
		//@TODO
	case errhttp.NotFound:
		//@TODO
	case errhttp.InternalServerError:
		//@TODO
		
	case errhttp.ClientError:
		//@TODO
	case errhttp.ServerError:
		//@TODO
		
	default:
		//@TODO
	}

Here is another example, where it used the .ErrHTTP() method to get the HTTP response status code:

	import "sourcecode.social/reiver/go-errhttp"
	
	// ...
	
	return errhttp.ErrBadRequest
	
	// ...
	
	switch casted := err.(type) {
	case errhttp.ClientError:
		statuscode := casted.ErrHTTP()
		
		http.Error(responsewriter, http.StatusText(statuscode), statuscode)
		return
	case errhttp.ServerError:
		statuscode := casted.ErrHTTP()

		http.Error(responsewriter, http.StatusText(statuscode), statuscode)
		return
	default:
		//@TODO
	}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExpectationFailed error = ClientErrorExpectationFailed
View Source
var ErrFailedDependency error = ClientErrorFailedDependency
View Source
var ErrGatewayTimeout error = ServerErrorGatewayTimeout
View Source
var ErrHTTPVersionNotSupported error = ServerErrorHTTPVersionNotSupported
View Source
var ErrInsufficientStorage error = ServerErrorInsufficientStorage
View Source
var ErrInternalServerError error = ServerErrorInternalServerError
View Source
var ErrLengthRequired error = ClientErrorLengthRequired
View Source
var ErrLoopDetected error = ServerErrorLoopDetected
View Source
var ErrMethodNotAllowed error = ClientErrorMethodNotAllowed
View Source
var ErrMisdirectedRequest error = ClientErrorMisdirectedRequest
View Source
var ErrNetworkAuthenticationRequired error = ServerErrorNetworkAuthenticationRequired
View Source
var ErrNotAcceptable error = ClientErrorNotAcceptable
View Source
var ErrNotImplemented error = ServerErrorNotImplemented
View Source
var ErrPaymentRequired error = ClientErrorPaymentRequired
View Source
var ErrPreconditionFailed error = ClientErrorPreconditionFailed
View Source
var ErrPreconditionRequired error = PreconditionRequiredWrap(nil)
View Source
var ErrProxyAuthRequired error = ClientErrorProxyAuthRequired
View Source
var ErrRequestEntityTooLarge error = ClientErrorRequestEntityTooLarge
View Source
var ErrRequestHeaderFieldsTooLarge error = ClientErrorRequestHeaderFieldsTooLarge
View Source
var ErrRequestTimeout error = ClientErrorRequestTimeout
View Source
var ErrRequestURITooLong error = ClientErrorRequestURITooLong
View Source
var ErrRequestedRangeNotSatisfiable error = ClientErrorRequestedRangeNotSatisfiable
View Source
var ErrServiceUnavailable error = ServerErrorServiceUnavailable
View Source
var ErrTooManyRequests error = ClientErrorTooManyRequests
View Source
var ErrUnauthorized error = ClientErrorUnauthorized
View Source
var ErrUnavailableForLegalReasons error = ClientErrorUnavailableForLegalReasons
View Source
var ErrUnprocessableEntity error = ClientErrorUnprocessableEntity
View Source
var ErrUnsupportedMediaType error = ClientErrorUnsupportedMediaType
View Source
var ErrUpgradeRequired error = ClientErrorUpgradeRequired
View Source
var ErrVariantAlsoNegotiates error = ServerErrorVariantAlsoNegotiates

Functions

func BadGatewayWrap

func BadGatewayWrap(err error) error

func BadRequestWrap

func BadRequestWrap(err error) error

func ConflictWrap

func ConflictWrap(err error) error

func ExpectationFailedWrap

func ExpectationFailedWrap(err error) error

func FailedDependencyWrap

func FailedDependencyWrap(err error) error

func ForbiddenWrap

func ForbiddenWrap(err error) error

func GatewayTimeoutWrap

func GatewayTimeoutWrap(err error) error

func GoneWrap

func GoneWrap(err error) error

func HTTPVersionNotSupportedWrap

func HTTPVersionNotSupportedWrap(err error) error

func InsufficientStorageWrap

func InsufficientStorageWrap(err error) error

func InternalServerErrorWrap

func InternalServerErrorWrap(err error) error

func LengthRequiredWrap

func LengthRequiredWrap(err error) error

func LockedWrap

func LockedWrap(err error) error

func LoopDetectedWrap

func LoopDetectedWrap(err error) error

func MethodNotAllowedWrap

func MethodNotAllowedWrap(err error) error

func MisdirectedRequestWrap

func MisdirectedRequestWrap(err error) error

func NetworkAuthenticationRequiredWrap

func NetworkAuthenticationRequiredWrap(err error) error

func NotAcceptableWrap

func NotAcceptableWrap(err error) error

func NotExtendedWrap

func NotExtendedWrap(err error) error

func NotFoundWrap

func NotFoundWrap(err error) error

func NotImplementedWrap

func NotImplementedWrap(err error) error

func PaymentRequiredWrap

func PaymentRequiredWrap(err error) error

func PreconditionFailedWrap

func PreconditionFailedWrap(err error) error

func PreconditionRequiredWrap

func PreconditionRequiredWrap(err error) error

func ProxyAuthRequiredWrap

func ProxyAuthRequiredWrap(err error) error

func RequestEntityTooLargeWrap

func RequestEntityTooLargeWrap(err error) error

func RequestHeaderFieldsTooLargeWrap

func RequestHeaderFieldsTooLargeWrap(err error) error

func RequestTimeoutWrap

func RequestTimeoutWrap(err error) error

func RequestURITooLongWrap

func RequestURITooLongWrap(err error) error

func RequestedRangeNotSatisfiableWrap

func RequestedRangeNotSatisfiableWrap(err error) error

func Return

func Return(statusCode int) error

Return returns the appropriate error based on the status code.

func ServiceUnavailableWrap

func ServiceUnavailableWrap(err error) error

func TeapotWrap

func TeapotWrap(err error) error

func TooEarlyWrap

func TooEarlyWrap(err error) error

func TooManyRequestsWrap

func TooManyRequestsWrap(err error) error

func UnauthorizedWrap

func UnauthorizedWrap(err error) error

func UnavailableForLegalReasonsWrap

func UnavailableForLegalReasonsWrap(err error) error

func UnprocessableEntityWrap

func UnprocessableEntityWrap(err error) error

func UnsupportedMediaTypeWrap

func UnsupportedMediaTypeWrap(err error) error

func UpgradeRequiredWrap

func UpgradeRequiredWrap(err error) error

func VariantAlsoNegotiatesWrap

func VariantAlsoNegotiatesWrap(err error) error

Types

type BadGateway

type BadGateway interface {
	ServerError
	BadGateway()
}

type BadRequest

type BadRequest interface {
	ClientError
	BadRequest()
}

type ClientError

type ClientError interface {
	Error
	ClientError()
}
var ClientErrorBadRequest ClientError = BadRequestWrap(nil).(BadRequest)
var ClientErrorConflict ClientError = ConflictWrap(nil).(Conflict)
var ClientErrorExpectationFailed ClientError = ExpectationFailedWrap(nil).(ExpectationFailed)
var ClientErrorFailedDependency ClientError = FailedDependencyWrap(nil).(FailedDependency)
var ClientErrorForbidden ClientError = ForbiddenWrap(nil).(Forbidden)
var ClientErrorGone ClientError = GoneWrap(nil).(Gone)
var ClientErrorLengthRequired ClientError = LengthRequiredWrap(nil).(LengthRequired)
var ClientErrorLocked ClientError = LockedWrap(nil).(Locked)
var ClientErrorMethodNotAllowed ClientError = MethodNotAllowedWrap(nil).(MethodNotAllowed)
var ClientErrorMisdirectedRequest ClientError = MisdirectedRequestWrap(nil).(MisdirectedRequest)
var ClientErrorNotAcceptable ClientError = NotAcceptableWrap(nil).(NotAcceptable)
var ClientErrorNotFound ClientError = NotFoundWrap(nil).(NotFound)
var ClientErrorPaymentRequired ClientError = PaymentRequiredWrap(nil).(PaymentRequired)
var ClientErrorPreconditionFailed ClientError = PreconditionFailedWrap(nil).(PreconditionFailed)
var ClientErrorProxyAuthRequired ClientError = ProxyAuthRequiredWrap(nil).(ProxyAuthRequired)
var ClientErrorRequestEntityTooLarge ClientError = RequestEntityTooLargeWrap(nil).(RequestEntityTooLarge)
var ClientErrorRequestHeaderFieldsTooLarge ClientError = RequestHeaderFieldsTooLargeWrap(nil).(RequestHeaderFieldsTooLarge)
var ClientErrorRequestTimeout ClientError = RequestTimeoutWrap(nil).(RequestTimeout)
var ClientErrorRequestURITooLong ClientError = RequestURITooLongWrap(nil).(RequestURITooLong)
var ClientErrorRequestedRangeNotSatisfiable ClientError = RequestedRangeNotSatisfiableWrap(nil).(RequestedRangeNotSatisfiable)
var ClientErrorTeapot ClientError = TeapotWrap(nil).(Teapot)
var ClientErrorTooEarly ClientError = TooEarlyWrap(nil).(TooEarly)
var ClientErrorTooManyRequests ClientError = TooManyRequestsWrap(nil).(TooManyRequests)
var ClientErrorUnauthorized ClientError = UnauthorizedWrap(nil).(Unauthorized)
var ClientErrorUnavailableForLegalReasons ClientError = UnavailableForLegalReasonsWrap(nil).(UnavailableForLegalReasons)
var ClientErrorUnprocessableEntity ClientError = UnprocessableEntityWrap(nil).(UnprocessableEntity)
var ClientErrorUnsupportedMediaType ClientError = UnsupportedMediaTypeWrap(nil).(UnsupportedMediaType)
var ClientErrorUpgradeRequired ClientError = UpgradeRequiredWrap(nil).(UpgradeRequired)

type Conflict

type Conflict interface {
	ClientError
	Conflict()
}

type Error

type Error interface {
	error
	ErrHTTP() int
	Unwrap() error
}
var ErrHTTPBadGateway Error = ServerErrorBadGateway
var ErrHTTPBadRequest Error = ClientErrorBadRequest
var ErrHTTPConflict Error = ClientErrorConflict
var ErrHTTPExpectationFailed Error = ClientErrorExpectationFailed
var ErrHTTPFailedDependency Error = ClientErrorFailedDependency
var ErrHTTPForbidden Error = ClientErrorForbidden
var ErrHTTPGatewayTimeout Error = ServerErrorGatewayTimeout
var ErrHTTPGone Error = ClientErrorGone
var ErrHTTPHTTPVersionNotSupported Error = ServerErrorHTTPVersionNotSupported
var ErrHTTPInsufficientStorage Error = ServerErrorInsufficientStorage
var ErrHTTPInternalServerError Error = ServerErrorInternalServerError
var ErrHTTPLengthRequired Error = ClientErrorLengthRequired
var ErrHTTPLocked Error = ClientErrorLocked
var ErrHTTPLoopDetected Error = ServerErrorLoopDetected
var ErrHTTPMethodNotAllowed Error = ClientErrorMethodNotAllowed
var ErrHTTPMisdirectedRequest Error = ClientErrorMisdirectedRequest
var ErrHTTPNetworkAuthenticationRequired Error = ServerErrorNetworkAuthenticationRequired
var ErrHTTPNotAcceptable Error = ClientErrorNotAcceptable
var ErrHTTPNotExtended Error = ServerErrorNotExtended
var ErrHTTPNotFound Error = ClientErrorNotFound
var ErrHTTPNotImplemented Error = ServerErrorNotImplemented
var ErrHTTPPaymentRequired Error = ClientErrorPaymentRequired
var ErrHTTPPreconditionFailed Error = ClientErrorPreconditionFailed
var ErrHTTPProxyAuthRequired Error = ClientErrorProxyAuthRequired
var ErrHTTPRequestEntityTooLarge Error = ClientErrorRequestEntityTooLarge
var ErrHTTPRequestHeaderFieldsTooLarge Error = ClientErrorRequestHeaderFieldsTooLarge
var ErrHTTPRequestTimeout Error = ClientErrorRequestTimeout
var ErrHTTPRequestURITooLong Error = ClientErrorRequestURITooLong
var ErrHTTPRequestedRangeNotSatisfiable Error = ClientErrorRequestedRangeNotSatisfiable
var ErrHTTPServiceUnavailable Error = ServerErrorServiceUnavailable
var ErrHTTPTeapot Error = ClientErrorTeapot
var ErrHTTPTooEarly Error = ClientErrorTooEarly
var ErrHTTPTooManyRequests Error = ClientErrorTooManyRequests
var ErrHTTPUnauthorized Error = ClientErrorUnauthorized
var ErrHTTPUnavailableForLegalReasons Error = ClientErrorUnavailableForLegalReasons
var ErrHTTPUnprocessableEntity Error = ClientErrorUnprocessableEntity
var ErrHTTPUnsupportedMediaType Error = ClientErrorUnsupportedMediaType
var ErrHTTPUpgradeRequired Error = ClientErrorUpgradeRequired
var ErrHTTPVariantAlsoNegotiates Error = ServerErrorVariantAlsoNegotiates

type ExpectationFailed

type ExpectationFailed interface {
	ClientError
	ExpectationFailed()
}

type FailedDependency

type FailedDependency interface {
	ClientError
	FailedDependency()
}

type Forbidden

type Forbidden interface {
	ClientError
	Forbidden()
}

type GatewayTimeout

type GatewayTimeout interface {
	ServerError
	GatewayTimeout()
}

type Gone

type Gone interface {
	ClientError
	Gone()
}

type HTTPVersionNotSupported

type HTTPVersionNotSupported interface {
	ServerError
	HTTPVersionNotSupported()
}

type InsufficientStorage

type InsufficientStorage interface {
	ServerError
	InsufficientStorage()
}

type InternalServerError

type InternalServerError interface {
	ServerError
	InternalServerError()
}
var ServerErrorInternalServerError InternalServerError = InternalServerErrorWrap(nil).(InternalServerError)

type LengthRequired

type LengthRequired interface {
	ClientError
	LengthRequired()
}

type Locked

type Locked interface {
	ClientError
	Locked()
}

type LoopDetected

type LoopDetected interface {
	ServerError
	LoopDetected()
}

type MethodNotAllowed

type MethodNotAllowed interface {
	ClientError
	MethodNotAllowed()
}

type MisdirectedRequest

type MisdirectedRequest interface {
	ClientError
	MisdirectedRequest()
}

type NetworkAuthenticationRequired

type NetworkAuthenticationRequired interface {
	ServerError
	NetworkAuthenticationRequired()
}

type NotAcceptable

type NotAcceptable interface {
	ClientError
	NotAcceptable()
}

type NotExtended

type NotExtended interface {
	ServerError
	NotExtended()
}

type NotFound

type NotFound interface {
	ClientError
	NotFound()
}

type NotImplemented

type NotImplemented interface {
	ServerError
	NotImplemented()
}

type PaymentRequired

type PaymentRequired interface {
	ClientError
	PaymentRequired()
}

type PreconditionFailed

type PreconditionFailed interface {
	ClientError
	PreconditionFailed()
}

type PreconditionRequired

type PreconditionRequired interface {
	ClientError
	PreconditionRequired()
}

type ProxyAuthRequired

type ProxyAuthRequired interface {
	ClientError
	ProxyAuthRequired()
}

type RequestEntityTooLarge

type RequestEntityTooLarge interface {
	ClientError
	RequestEntityTooLarge()
}

type RequestHeaderFieldsTooLarge

type RequestHeaderFieldsTooLarge interface {
	ClientError
	RequestHeaderFieldsTooLarge()
}

type RequestTimeout

type RequestTimeout interface {
	ClientError
	RequestTimeout()
}

type RequestURITooLong

type RequestURITooLong interface {
	ClientError
	RequestURITooLong()
}

type RequestedRangeNotSatisfiable

type RequestedRangeNotSatisfiable interface {
	ClientError
	RequestedRangeNotSatisfiable()
}

type ServerError

type ServerError interface {
	Error
	ServerError()
}
var ServerErrorBadGateway ServerError = BadGatewayWrap(nil).(BadGateway)
var ServerErrorGatewayTimeout ServerError = GatewayTimeoutWrap(nil).(GatewayTimeout)
var ServerErrorHTTPVersionNotSupported ServerError = HTTPVersionNotSupportedWrap(nil).(HTTPVersionNotSupported)
var ServerErrorInsufficientStorage ServerError = InsufficientStorageWrap(nil).(InsufficientStorage)
var ServerErrorLoopDetected ServerError = LoopDetectedWrap(nil).(LoopDetected)
var ServerErrorNetworkAuthenticationRequired ServerError = NetworkAuthenticationRequiredWrap(nil).(NetworkAuthenticationRequired)
var ServerErrorNotExtended ServerError = NotExtendedWrap(nil).(NotExtended)
var ServerErrorNotImplemented ServerError = NotImplementedWrap(nil).(NotImplemented)
var ServerErrorServiceUnavailable ServerError = ServiceUnavailableWrap(nil).(ServiceUnavailable)
var ServerErrorVariantAlsoNegotiates ServerError = VariantAlsoNegotiatesWrap(nil).(VariantAlsoNegotiates)

type ServiceUnavailable

type ServiceUnavailable interface {
	ServerError
	ServiceUnavailable()
}

type Teapot

type Teapot interface {
	ClientError
	Teapot()
}

type TooEarly

type TooEarly interface {
	ClientError
	TooEarly()
}

type TooManyRequests

type TooManyRequests interface {
	ClientError
	TooManyRequests()
}

type Unauthorized

type Unauthorized interface {
	ClientError
	Unauthorized()
}

type UnavailableForLegalReasons

type UnavailableForLegalReasons interface {
	ClientError
	UnavailableForLegalReasons()
}

type UnprocessableEntity

type UnprocessableEntity interface {
	ClientError
	UnprocessableEntity()
}

type UnsupportedMediaType

type UnsupportedMediaType interface {
	ClientError
	UnsupportedMediaType()
}

type UpgradeRequired

type UpgradeRequired interface {
	ClientError
	UpgradeRequired()
}

type VariantAlsoNegotiates

type VariantAlsoNegotiates interface {
	ServerError
	VariantAlsoNegotiates()
}

Jump to

Keyboard shortcuts

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