Documentation ¶
Index ¶
- func StatusCodeFromCode(code int) int
- type Error
- type ErrorField
- type ErrorFields
- type ServiceCode
- type StatusErr
- func FromErr(err error) *StatusErr
- func IsStatusErr(err error) (*StatusErr, bool)
- func NewStatusErr(key string, code int, msg string) *StatusErr
- func NewUnknownErr() *StatusErr
- func ParseStatusErrSummary(s string) (*StatusErr, error)
- func Wrap(err error, code int, key string, msgs ...string) *StatusErr
- func (se StatusErr) AppendErrorField(in string, field string, msg string) *StatusErr
- func (se StatusErr) AppendErrorFields(errorFields ...*ErrorField) *StatusErr
- func (se StatusErr) AppendSource(sourceName string) *StatusErr
- func (se StatusErr) DisableErrTalk() *StatusErr
- func (se StatusErr) EnableErrTalk() *StatusErr
- func (se *StatusErr) Error() string
- func (se *StatusErr) Is(err error) bool
- func (se *StatusErr) StatusCode() int
- func (se *StatusErr) Summary() string
- func (se StatusErr) WithDesc(desc string) *StatusErr
- func (se StatusErr) WithID(id string) *StatusErr
- func (se StatusErr) WithMsg(msg string) *StatusErr
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StatusCodeFromCode ¶
Types ¶
type ErrorField ¶
type ErrorField struct { Field string `json:"field" xml:"field"` // Field path: prop.slice[2].a Msg string `json:"msg" xml:"msg"` // Msg message In string `json:"in" xml:"in"` // In location eq. body, query, header, path, formData }
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 (fs ErrorFields) Len() int
func (ErrorFields) Less ¶
func (fs ErrorFields) Less(i, j int) bool
func (ErrorFields) String ¶
func (fs ErrorFields) String() string
func (ErrorFields) Swap ¶
func (fs ErrorFields) Swap(i, j int)
type ServiceCode ¶
type ServiceCode interface {
ServiceCode() int
}
type StatusErr ¶
type StatusErr struct { Key string `json:"key" xml:"key"` // key of err Code int `json:"code" xml:"code"` // unique err code Msg string `json:"msg" xml:"msg"` // msg of err Desc string `json:"desc" xml:"desc"` // desc of err CanBeTalk bool `json:"canBeTalk" xml:"canBeTalk"` // can be task error; for client to should error msg to end user ID string `json:"id" xml:"id"` // request ID or other request context Sources []string `json:"sources" xml:"sources"` // error tracing Fields ErrorFields `json:"fields" xml:"fields"` // error in where fields // contains filtered or unexported fields }
Example ¶
fmt.Println(Unauthorized) fmt.Println(statusx.FromErr(nil)) fmt.Println(statusx.FromErr(fmt.Errorf("unknown"))) fmt.Println(Unauthorized.StatusErr().WithMsg("msg overwrite")) fmt.Println(Unauthorized.StatusErr().WithDesc("desc overwrite")) fmt.Println(Unauthorized.StatusErr().DisableErrTalk().EnableErrTalk()) fmt.Println(Unauthorized.StatusErr().WithID("111")) fmt.Println(Unauthorized.StatusErr().AppendSource("service-abc")) fmt.Println(Unauthorized.StatusErr().AppendErrorField("header", "Authorization", "missing")) fmt.Println(Unauthorized.StatusErr().AppendErrorFields( statusx.NewErrorField("query", "key", "missing"), statusx.NewErrorField("header", "Authorization", "missing"), ))
Output: []@StatusErr[Unauthorized][401999001][Unauthorized]! <nil> []@StatusErr[UnknownError][500000000][unknown error] unknown []@StatusErr[Unauthorized][401999001][msg overwrite]! []@StatusErr[Unauthorized][401999001][Unauthorized]! desc overwrite []@StatusErr[Unauthorized][401999001][Unauthorized]! []@StatusErr[Unauthorized][401999001][Unauthorized]! [service-abc]@StatusErr[Unauthorized][401999001][Unauthorized]! []@StatusErr[Unauthorized][401999001][Unauthorized]!<Authorization in header - missing> []@StatusErr[Unauthorized][401999001][Unauthorized]!<Authorization in header - missing, key in query - missing>
func IsStatusErr ¶
func NewUnknownErr ¶
func NewUnknownErr() *StatusErr
func ParseStatusErrSummary ¶
func (StatusErr) AppendErrorField ¶
func (StatusErr) AppendErrorFields ¶
func (se StatusErr) AppendErrorFields(errorFields ...*ErrorField) *StatusErr
func (StatusErr) AppendSource ¶
func (StatusErr) DisableErrTalk ¶
func (StatusErr) EnableErrTalk ¶
func (*StatusErr) StatusCode ¶
Click to show internal directories.
Click to hide internal directories.