weberr

package module
v0.1.1 Latest Latest
Warning

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

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

README

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

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 - HTTP internal Error - code 500
	NoType ErrorType = http.StatusInternalServerError
	// BadRequest error - Code 400
	BadRequest ErrorType = http.StatusBadRequest
	// NotFound error - Code 404
	NotFound ErrorType = http.StatusNotFound
	// Unauthorized error - Code 401
	Unauthorized ErrorType = http.StatusUnauthorized
	// Conflict - Code 409
	Conflict ErrorType = http.StatusConflict
)

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