weberr

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2019 License: BSD-2-Clause Imports: 3 Imported by: 40

README

weberr logo

weberr

Package weberr based on https://github.com/pkg/errors with a few additions:

  • Set an error type that corresponds to HTTP status returned by this error
  • Set a user friendly error message (in addition to the error message that will be logged)

Go Report Card Build Status GoDoc License

go get github.com/zgalor/weberr

Read the package documentation for more information.

License

BSD-2-Clause

[ awesome logo image by gophers... ]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Errorf

func Errorf(msg string, args ...interface{}) error

Errorf returns an error with format string

func GetStackTrace

func GetStackTrace(err error) string

GetStackTrace returns the stack trace starting from the first error that has been wrapped / created

func GetUserMessage

func GetUserMessage(err error) string

GetUserMessage returns user readable error message for all errors If error is not `userMessager` returns empty string

func UserErrorf

func UserErrorf(msg string, args ...interface{}) error

UserErrorf returns an error with format string

func UserWrapf

func UserWrapf(err error, msg string, args ...interface{}) error

UserWrapf adds a user readable to an error

func Wrapf

func Wrapf(err error, msg string, args ...interface{}) error

Wrapf return an error with format string

Types

type ErrorType

type ErrorType uint

ErrorType is the type of an error

const (
	// NoType error - Default placeholder for un-typed errors
	NoType ErrorType = http.StatusInternalServerError

	// 4xx Client errors
	// -----------------
	// BadRequest error - Code 400
	BadRequest ErrorType = http.StatusBadRequest
	// Unauthorized error - Code 401
	Unauthorized ErrorType = http.StatusUnauthorized
	// PaymentRequired error - Code 402
	PaymentRequired ErrorType = http.StatusPaymentRequired
	// Forbidden error - Code 403
	Forbidden ErrorType = http.StatusForbidden
	// NotFound error - Code 404
	NotFound ErrorType = http.StatusNotFound
	// MethodNotAllowed error - Code 405
	MethodNotAllowed ErrorType = http.StatusMethodNotAllowed
	// NotAcceptable error - Code 406
	NotAcceptable ErrorType = http.StatusNotAcceptable
	// ProxyAuthRequired error - Code 407
	ProxyAuthRequired ErrorType = http.StatusProxyAuthRequired
	// RequestTimeout error - Code 408
	RequestTimeout ErrorType = http.StatusRequestTimeout
	// Conflict error - Code 409
	Conflict ErrorType = http.StatusConflict
	// Gone error - Code 410
	Gone ErrorType = http.StatusGone
	// LengthRequired error - Code 411
	LengthRequired ErrorType = http.StatusLengthRequired
	// PreconditionFailed error - Code 412
	PreconditionFailed ErrorType = http.StatusPreconditionFailed
	// RequestEntityTooLarge error - Code 413
	RequestEntityTooLarge ErrorType = http.StatusRequestEntityTooLarge
	// RequestURITooLong error - Code 414
	RequestURITooLong ErrorType = http.StatusRequestURITooLong
	// UnsupportedMediaType error - Code 415
	UnsupportedMediaType ErrorType = http.StatusUnsupportedMediaType
	// RequestedRangeNotSatisfiable error - Code 416
	RequestedRangeNotSatisfiable ErrorType = http.StatusRequestedRangeNotSatisfiable
	// ExpectationFailed error - Code 417
	ExpectationFailed ErrorType = http.StatusExpectationFailed
	// Teapot error - Code 418
	Teapot ErrorType = http.StatusTeapot
	// UnprocessableEntity error - Code 422
	UnprocessableEntity ErrorType = http.StatusUnprocessableEntity
	// Locked error - Code 423
	Locked ErrorType = http.StatusLocked
	// FailedDependency error - Code 424
	FailedDependency ErrorType = http.StatusFailedDependency
	// UpgradeRequired error - Code 426
	UpgradeRequired ErrorType = http.StatusUpgradeRequired
	// PreconditionRequired error - Code 428
	PreconditionRequired ErrorType = http.StatusPreconditionRequired
	// TooManyRequests error - Code 429
	TooManyRequests ErrorType = http.StatusTooManyRequests
	// RequestHeaderFieldsTooLarge error - Code 431
	RequestHeaderFieldsTooLarge ErrorType = http.StatusRequestHeaderFieldsTooLarge
	// UnavailableForLegalReasons error - Code 451
	UnavailableForLegalReasons ErrorType = http.StatusUnavailableForLegalReasons

	// 5xx Server errors
	// -----------------
	// InternalServerError error - Code 500
	InternalServerError ErrorType = http.StatusInternalServerError
	// NotImplemented error - Code 501
	NotImplemented ErrorType = http.StatusNotImplemented
	// BadGateway error - Code 502
	BadGateway ErrorType = http.StatusBadGateway
	// ServiceUnavailable error - Code 503
	ServiceUnavailable ErrorType = http.StatusServiceUnavailable
	// GatewayTimeout error - Code 504
	GatewayTimeout ErrorType = http.StatusGatewayTimeout
	// HTTPVersionNotSupported error - Code 505
	HTTPVersionNotSupported ErrorType = http.StatusHTTPVersionNotSupported
	// VariantAlsoNegotiates error - Code 506
	VariantAlsoNegotiates ErrorType = http.StatusVariantAlsoNegotiates
	// InsufficientStorage error - Code 507
	InsufficientStorage ErrorType = http.StatusInsufficientStorage
	// LoopDetected error - Code 508
	LoopDetected ErrorType = http.StatusLoopDetected
	// NotExtended error - Code 510
	NotExtended ErrorType = http.StatusNotExtended
	// NetworkAuthenticationRequired error - Code 511
	NetworkAuthenticationRequired ErrorType = http.StatusNetworkAuthenticationRequired
)

func GetType

func GetType(err error) ErrorType

GetType returns the error type for all errors if error is not `typed` - it returns NoType

func (ErrorType) Errorf

func (errorType ErrorType) Errorf(msg string, args ...interface{}) error

Errorf creates a new customError with formatted message

func (ErrorType) Set

func (errorType ErrorType) Set(err error) error

Set the type of the error

func (ErrorType) UserErrorf

func (errorType ErrorType) UserErrorf(msg string, args ...interface{}) error

UserErrorf creates a new error with a user message

func (ErrorType) UserWrapf

func (errorType ErrorType) UserWrapf(err error, msg string, args ...interface{}) error

UserWrapf adds a user readable to an error

func (ErrorType) Wrapf

func (errorType ErrorType) Wrapf(err error, msg string, args ...interface{}) error

Wrapf creates a new wrapped error with formatted message

Jump to

Keyboard shortcuts

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