errno

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2019 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Common errors
	// ------------------------------------------
	// 成功
	OK = &Errno{Code: 0, Message: "OK"}
	// 服务器错误
	InternalServerError = &Errno{Code: 10001, Message: "Internal app error"}
	ErrBind             = &Errno{Code: 10002, Message: "Error occurred while binding the request body to the struct."}

	// 数据库错误
	ErrDatabase   = &Errno{Code: 20002, Message: "Database error."}
	ErrValidation = &Errno{Code: 20001, Message: "Validation failed."}

	// 用户错误
	// --------------------------------------------
	ErrEncrypt      = &Err{Code: 20101, Message: "对用户密码进行加密时发生错误"}
	ErrUserNotFound = &Err{Code: 20102, Message: "此用户找不到"}
)

Functions

func DecodeErr

func DecodeErr(err error) (int, string)

解析定制错误

func IsErrUserNotFound

func IsErrUserNotFound(err error) bool

Types

type Err

type Err struct {
	Code    int
	Message string
	Err     error
}

Err represents an error

func New

func New(errno *Errno, err error) *Err

新建定制错误

func (*Err) Add

func (err *Err) Add(message string) error

func (*Err) Addf

func (err *Err) Addf(format string, args ...interface{}) error

func (*Err) Error

func (err *Err) Error() string

type Errno

type Errno struct {
	Code    int
	Message string
}

func (Errno) Error

func (err Errno) Error() string

Jump to

Keyboard shortcuts

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