kratos: Index | Files | Directories

package ecode

import ""


Package Files

common_ecode.go ecode.go status.go


var (
    OK  = add(0) // 正确

    NotModified        = add(-304) // 木有改动
    TemporaryRedirect  = add(-307) // 撞车跳转
    RequestErr         = add(-400) // 请求错误
    Unauthorized       = add(-401) // 未认证
    AccessDenied       = add(-403) // 访问权限不足
    NothingFound       = add(-404) // 啥都木有
    MethodNotAllowed   = add(-405) // 不支持该方法
    Conflict           = add(-409) // 冲突
    Canceled           = add(-498) // 客户端取消请求
    ServerErr          = add(-500) // 服务器错误
    ServiceUnavailable = add(-503) // 过载保护,服务暂不可用
    Deadline           = add(-504) // 服务调用超时
    LimitExceed        = add(-509) // 超出限制

All common ecode

func Equal Uses

func Equal(a, b Codes) bool

Equal equal a and b by code int.

func EqualError Uses

func EqualError(code Codes, err error) bool

EqualError equal error

func Register Uses

func Register(cm map[int]string)

Register register ecode message map.

type Code Uses

type Code int

A Code is an int error code spec.

func Int Uses

func Int(i int) Code

Int parse code int to error.

func New Uses

func New(e int) Code

New new a ecode.Codes by int value. NOTE: ecode must unique in global, the New will check repeat and then panic.

func String Uses

func String(e string) Code

String parse code string to error.

func (Code) Code Uses

func (e Code) Code() int

Code return error code

func (Code) Details Uses

func (e Code) Details() []interface{}

Details return details.

func (Code) Error Uses

func (e Code) Error() string

func (Code) Message Uses

func (e Code) Message() string

Message return error message

type Codes Uses

type Codes interface {
    // sometimes Error return Code in string form
    // NOTE: don't use Error in monitor report even it also work for now
    Error() string
    // Code get error code.
    Code() int
    // Message get code message.
    Message() string
    //Detail get error detail,it may be nil.
    Details() []interface{}

Codes ecode error interface which has a code & message.

func Cause Uses

func Cause(e error) Codes

Cause cause from error to ecode.

func FromProto Uses

func FromProto(pbMsg proto.Message) Codes

FromProto new status from grpc detail

type Status Uses

type Status struct {
    // contains filtered or unexported fields

Status statusError is an alias of a status proto implement ecode.Codes

func Error Uses

func Error(code Code, message string) *Status

Error new status with code and message

func Errorf Uses

func Errorf(code Code, format string, args ...interface{}) *Status

Errorf new status with code and message

func FromCode Uses

func FromCode(code Code) *Status

FromCode create status from ecode

func (*Status) Code Uses

func (s *Status) Code() int

Code return error code

func (*Status) Details Uses

func (s *Status) Details() []interface{}

Details return error details

func (*Status) Error Uses

func (s *Status) Error() string

Error implement error

func (*Status) Message Uses

func (s *Status) Message() string

Message return error message for developer

func (*Status) Proto Uses

func (s *Status) Proto() *types.Status

Proto return origin protobuf message

func (*Status) WithDetails Uses

func (s *Status) WithDetails(pbs ...proto.Message) (*Status, error)

WithDetails WithDetails



Package ecode imports 7 packages (graph) and is imported by 13 packages. Updated 2020-03-29. Refresh now. Tools for package owners.