berror

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Unknown = DefineCode(5000001, "error", "Unknown", fmt.Sprintf(`
Unknown error code. Usually you will see this code in three cases:
1. You forget to define Code or function DefineCode not being executed;
2. This is not Beego's error but you call FromError();
3. Beego got unexpected error and don't know how to handle it, and then return Unknown error

A common practice to DefineCode looks like:
%s

In this way, you may forget to import this package, and got Unknown error. 

Sometimes, you believe you got Beego error, but actually you don't, and then you call FromError(err)

`, goCodeBlock(`
import your_package

func init() {
    DefineCode(5100100, "your_module", "detail")
    // ...
}
`)))

Unknown indicates got some error which is not defined

Functions

func Error

func Error(c Code, msg string) error

Error returns an error representing c and msg. If c is OK, returns nil.

func Errorf

func Errorf(c Code, format string, a ...interface{}) error

Errorf returns error

func Wrap

func Wrap(err error, c Code, msg string) error

func Wrapf

func Wrapf(err error, c Code, format string, a ...interface{}) error

Types

type Code

type Code interface {
	Code() uint32
	Module() string
	Desc() string
	Name() string
}

A Code is an unsigned 32-bit error code as defined in the beego spec.

func DefineCode

func DefineCode(code uint32, module string, name string, desc string) Code

DefineCode defining a new Code Before defining a new code, please read Beego specification. desc could be markdown doc

func FromError

func FromError(err error) (Code, bool)

FromError is very simple. It just parse error msg and check whether code has been register if code not being register, return unknown if err.Error() is not valid beego error code, return unknown

Jump to

Keyboard shortcuts

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