coderr

package
v1.2.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Invalid           Code = -1
	Ok                     = 0
	InvalidParams          = http.StatusBadRequest
	BadRequest             = http.StatusBadRequest
	NotFound               = http.StatusNotFound
	TooManyRequests        = http.StatusTooManyRequests
	Internal               = http.StatusInternalServerError
	ErrNotImplemented      = http.StatusNotImplemented

	// HTTPCodeUpperBound is a bound under which any Code should have the same meaning with the http status code.
	HTTPCodeUpperBound   = Code(1000)
	PrintHelpUsage       = 1001
	ClusterAlreadyExists = 1002
)

Variables

This section is empty.

Functions

func Is

func Is(err error, expectCode Code) bool

Is checks whether the cause of `err` is the kind of error specified by the `expectCode`. Returns false if the cause of `err` is not CodeError.

Types

type Code

type Code int

func GetCauseCode

func GetCauseCode(err error) (Code, bool)

func (Code) ToHTTPCode

func (c Code) ToHTTPCode() int

ToHTTPCode converts the Code to http code. The Code below the HTTPCodeUpperBound has the same meaning as the http status code. However, for the other codes, we should define the conversion rules by ourselves.

type CodeError

type CodeError interface {
	error
	Code() Code
	// WithCausef should generate a new CodeError instance with the provided cause details.
	WithCausef(format string, a ...any) CodeError
	// WithCause should generate a new CodeError instance with the provided cause details.
	WithCause(cause error) CodeError
}

CodeError is an error with code.

func NewCodeError

func NewCodeError(code Code, desc string) CodeError

NewCodeError creates a base CodeError definition. The provided code should be defined in the code.go in this package.

Jump to

Keyboard shortcuts

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