Documentation
¶
Index ¶
- Variables
- func DecodeErr(err error) (int, string)
- func Errorf(msg string, args ...interface{}) error
- func NewDetails(details map[string]any) proto.Message
- func SetHTTPStatusCode(err *Error, status int)
- func Stack(calldepth int) []byte
- func ToHTTPStatusCode(code int) int
- func ToRPCCode(code int) codes.Code
- type Err
- type Error
- type GrpcStatus
- type StackError
Constants ¶
This section is empty.
Variables ¶
var ( // 预定义错误 // Common errors Success = NewError(0, "Ok") ErrInternalServer = NewError(10000, "Internal server error") ErrInvalidParam = NewError(10001, "Invalid params") ErrNotFound = NewError(10003, "Not found") ErrUnknown = NewError(10004, "Unknown") ErrDeadlineExceeded = NewError(10005, "Deadline exceeded") ErrAccessDenied = NewError(10006, "Access denied") ErrLimitExceed = NewError(10007, "Beyond limit") ErrMethodNotAllowed = NewError(10008, "Method not allowed") ErrSignParam = NewError(10011, "Invalid sign") ErrValidation = NewError(10012, "Validation failed") ErrDatabase = NewError(10013, "Database error") ErrToken = NewError(10014, "Gen token error") ErrInvalidToken = NewError(10015, "Invalid token") ErrTokenTimeout = NewError(10016, "Token timeout") ErrTooManyRequests = NewError(10017, "Too many request") ErrInvalidTransaction = NewError(10018, "Invalid transaction") ErrEncrypt = NewError(10019, "Encrypting the user password error") )
nolint: golint
Functions ¶
func SetHTTPStatusCode ¶
SetHTTPStatusCode set a specific http status code to err
func ToHTTPStatusCode ¶
ToHTTPStatusCode convert custom error code to http status code and avoid return unknown status code.
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error 返回错误码和消息的结构体 nolint: govet
func (*Error) WithDetails ¶
WithDetails return err with detail
type GrpcStatus ¶
type GrpcStatus struct {
// contains filtered or unexported fields
}
GrpcStatus grpc error
func (*GrpcStatus) Status ¶
func (g *GrpcStatus) Status(details ...proto.Message) *status.Status
Status .
func (*GrpcStatus) WithDetails ¶
func (g *GrpcStatus) WithDetails(details ...proto.Message) *GrpcStatus
WithDetails .
type StackError ¶ added in v1.1.3
This package exposes some handy traceback functionality buried in the runtime.
It can also be used to provide context to errors reducing the temptation to panic carelessly, just to get stack information.
The theory is that most errors that are created with the fmt.Errorf style are likely to be rare, but require more context to debug properly. The additional cost of computing a stack trace is therefore negligible.