errs

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHTTPCode

func GetHTTPCode(err error) int

GetHTTPCode returns an HTTP status code that corresponds to the ErrorType.

func New

func New(args ...interface{}) error

New builds an error value from its arguments. The type of each argument determines its meaning. If more than one argument of a given type is presented, only the last one is recorded.

The types are:

string
	Treated as an error message and assigned to the
	Err field after a call to errors.New
errs.ErrorType
	The class of error, such as not found
error
	The underlying error that triggered this one

If the error is printed, only those items that have been set to non-zero values will appear in the result

If Type is not specified or Other, we set it to the Type of the underlying error

func TypeIs

func TypeIs(t ErrorType, err error) bool

TypeIs reports whether err is an *Error of the given Type. If err is nil then TypeIs returns false.

Types

type Error

type Error struct {
	Type ErrorType
	Err  error
}

Error represents an error that has a type.

func (*Error) Error

func (e *Error) Error() string

Error returns the error message.

type ErrorType

type ErrorType uint8

ErrorType defines the type of the error.

const (
	Other        ErrorType = iota // Unclassified error
	NotFound                      // Item does not exist
	BadRequest                    // A remote REST call returned HTTP 400
	Unauthorized                  // Request is unauthorized to perform this call
)

Types of errors.

The values of the error types are common for the whole app. Do not reorder this list or remove any items since that will change their values. New items must be added only to the end

Jump to

Keyboard shortcuts

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