Documentation ¶
Index ¶
- Constants
- Variables
- func DemoErr() error
- type ErrorField
- type ErrorFields
- type StatusError
- func (statusErr *StatusError) Error() string
- func (statusErr *StatusError) HttpCode() int
- func (statusErr *StatusError) Is(err error) bool
- func (statusErr *StatusError) Status() int
- func (statusErr *StatusError) String() string
- func (statusErr StatusError) WithDesc(desc string) *StatusError
- func (statusErr StatusError) WithErrTalk() *StatusError
- func (statusErr StatusError) WithErrorField(in string, field string, msg string) *StatusError
- func (statusErr StatusError) WithErrorFields(errorFields ...*ErrorField) *StatusError
- func (statusErr StatusError) WithID(id string) *StatusError
- func (statusErr StatusError) WithMsg(msg string) *StatusError
- func (statusErr StatusError) WithSource(sourceName string) *StatusError
- func (statusErr StatusError) WithoutErrTalk() *StatusError
- type StatusErrorCode
- type StatusErrorCodeMap
Constants ¶
View Source
const DefaultErrorCode = 500000001
View Source
const DefaultErrorKey = "InternalError"
Variables ¶
View Source
var RegexpStatusError = regexp.MustCompile(`@httpError\(([0-9]+),(.+),"(.+)?","(.+)?",(false|true)\);`)
code, key, msg, desc, canBeTalkError
View Source
var StatusErrorCodes = StatusErrorCodeMap{}
Functions ¶
Types ¶
type ErrorField ¶
type ErrorField struct { // 出错字段路径 // 这个信息为一个 json 字符串,方便客户端进行定位错误原因 // 例如输入中 {"name":{ "alias" : "test"}} 中的alias出错,则返回 "name.alias" // 如果alias是数组, 且第2个元素的a字段错误,则返回"name.alias[2].a" Field string `json:"field" xml:"field"` // 错误信息 Msg string `json:"msg" xml:"msg"` // 错误字段位置 // body, query, header, path, formData In string `json:"in" xml:"in"` }
func NewErrorField ¶
func NewErrorField(in string, field string, msg string) *ErrorField
func (ErrorField) String ¶
func (s ErrorField) String() string
type ErrorFields ¶
type ErrorFields []*ErrorField
func (ErrorFields) Len ¶
func (fields ErrorFields) Len() int
func (ErrorFields) Less ¶
func (fields ErrorFields) Less(i, j int) bool
func (ErrorFields) Sort ¶
func (fields ErrorFields) Sort() ErrorFields
func (ErrorFields) String ¶
func (fields ErrorFields) String() string
func (ErrorFields) Swap ¶
func (fields ErrorFields) Swap(i, j int)
type StatusError ¶
type StatusError struct { // 错误 Key Key string `json:"key" xml:"key"` // 错误代码 Code int64 `json:"code" xml:"code"` // 错误信息 Msg string `json:"msg" xml:"msg"` // 详细描述 Desc string `json:"desc" xml:"desc"` // 是否能作为错误话术 CanBeErrorTalk bool `json:"canBeTalkError" xml:"canBeTalkError"` // 错误溯源 Source []string `json:"source" xml:"source"` // 请求 ID ID string `json:"id" xml:"id"` // 出错字段 ErrorFields ErrorFields `json:"errorFields" xml:"errorFields"` }
func FromError ¶
func FromError(err error) *StatusError
func ParseString ¶
func ParseString(s string) *StatusError
func (*StatusError) Error ¶
func (statusErr *StatusError) Error() string
func (*StatusError) Is ¶
func (statusErr *StatusError) Is(err error) bool
func (*StatusError) Status ¶
func (statusErr *StatusError) Status() int
func (*StatusError) String ¶
func (statusErr *StatusError) String() string
func (StatusError) WithDesc ¶
func (statusErr StatusError) WithDesc(desc string) *StatusError
func (StatusError) WithErrTalk ¶
func (statusErr StatusError) WithErrTalk() *StatusError
func (StatusError) WithErrorField ¶
func (statusErr StatusError) WithErrorField(in string, field string, msg string) *StatusError
func (StatusError) WithErrorFields ¶
func (statusErr StatusError) WithErrorFields(errorFields ...*ErrorField) *StatusError
func (StatusError) WithID ¶
func (statusErr StatusError) WithID(id string) *StatusError
func (StatusError) WithMsg ¶
func (statusErr StatusError) WithMsg(msg string) *StatusError
func (StatusError) WithSource ¶
func (statusErr StatusError) WithSource(sourceName string) *StatusError
func (StatusError) WithoutErrTalk ¶
func (statusErr StatusError) WithoutErrTalk() *StatusError
type StatusErrorCode ¶
type StatusErrorCode int64
const ( // 内部未明确定义的错误 UnknownError StatusErrorCode = http.StatusInternalServerError*1e6 + 1 + iota // 内部用于接收参数时非法的结构 InvalidStruct // Read 调用时发生错误 ReadFailed // 请求参数错误 InvalidRequestParams // HTTP 请求下游失败 HttpRequestFailed // 内部参数错误 InternalParams // 请求 url 错误 ProtocolParseFailed // 请求超时 RequestTimeout )
const ( // @errTalk 请求 JSON 格式错误 InvalidBodyStruct StatusErrorCode = http.StatusBadRequest*1e6 + 1 + iota // @errTalk 请求参数格式错误 InvalidNonBodyParameters // @errTalk 请求参数格式不匹配 InvalidField // @errTalk 解析表单数据失败 ParseFormFailed // @errTalk 读取表单文件数据失败 ReadFormFileFailed // @errTalk 非法签名 InvalidSecret )
const ( // @errTalk 验签失败 SignFailed StatusErrorCode = http.StatusUnauthorized*1e6 + 1 + iota )
const ( // http method 不允许 StatusMethodNotAllowed StatusErrorCode = http.StatusMethodNotAllowed*1e6 + 1 + iota )
func (StatusErrorCode) Error ¶
func (code StatusErrorCode) Error() string
func (StatusErrorCode) Is ¶
func (code StatusErrorCode) Is(err error) bool
func (StatusErrorCode) StatusError ¶
func (code StatusErrorCode) StatusError() *StatusError
type StatusErrorCodeMap ¶
type StatusErrorCodeMap map[int64]StatusError
func (StatusErrorCodeMap) Merge ¶
func (statusErrorCodeMap StatusErrorCodeMap) Merge(targetStatusErrorCodeMap StatusErrorCodeMap) StatusErrorCodeMap
func (StatusErrorCodeMap) String ¶
func (statusErrorCodeMap StatusErrorCodeMap) String() string
Source Files ¶
Click to show internal directories.
Click to hide internal directories.