gerror

package
v1.5.8 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorType_name = map[int32]string{
	0:      "OK",
	100000: "CUSTOM_ERROR",
	100001: "SERVER_INTERNAL_ERROR",
	100002: "SERVER_CDATA_ERROR",
	100003: "SERVER_CMSG_ERROR",
	100004: "SERVER_FILE_NOT_FOUND",
	100005: "SERVER_ACCESS_REFUSED",
	200000: "CLIENT_TIMEOUT",
	200001: "CLIENT_IO_ERROR",
}
View Source
var RecoverPanicToErr = true

Functions

func EnumName

func EnumName(m map[int32]string, v int32) string

EnumName is a helper function to simplify printing enums by name. Given an enum map and a value, it returns a useful string.

func IsCustomError

func IsCustomError(e ErrorType) bool

判断错误类型是否是允许的错误范围 true=消息内部定义的错误,false=系统级别错误,需要关闭连接

func PanicToErr

func PanicToErr(err *error)

func PanicValToErr

func PanicValToErr(panicVal interface{}, err *error)

Types

type ErrorType

type ErrorType int32
const (
	//操作成功的返回码常量
	OK ErrorType = 0

	//通用错误
	CUSTOM_ERROR ErrorType = 100000
	//服务器端一般错误
	SERVER_INTERNAL_ERROR ErrorType = 100001
	//读取客户端发送的数据异常
	SERVER_CDATA_ERROR ErrorType = 100002
	//处理客户端发送的数据异常
	SERVER_CMSG_ERROR ErrorType = 100003
	//服务器端的文件没有找到
	SERVER_FILE_NOT_FOUND ErrorType = 100004
	//服务器端的访问被拒绝
	SERVER_ACCESS_REFUSED ErrorType = 100005

	//客户端访问超时
	CLIENT_TIMEOUT ErrorType = 200000
	//客户端IO错误
	CLIENT_IO_ERROR ErrorType = 200001
)

func (ErrorType) String

func (x ErrorType) String() string

func (ErrorType) Value

func (x ErrorType) Value() int32

type SysError

type SysError struct {
	Code    ErrorType   `json:"code"`
	Content string      `json:"message,omitempty"`
	Cause   error       `json:"-"`
	Data    interface{} `json:"data,omitempty"`
}

系统常规错误

func New

func New(code ErrorType, err error) *SysError

func NewError

func NewError(code ErrorType, err string) *SysError

func NewErrorByCode

func NewErrorByCode(code ErrorType) *SysError

func (*SysError) Error

func (err *SysError) Error() string

Jump to

Keyboard shortcuts

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