statusx

package
v1.6.4 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func StatusCodeFromCode

func StatusCodeFromCode(code int) int

Types

type Error

type Error interface {
	StatusErr() *StatusErr
	Error() string
}

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 FromErr

func FromErr(err error) *StatusErr

func IsStatusErr

func IsStatusErr(err error) (*StatusErr, bool)

func NewStatusErr

func NewStatusErr(key string, code int, msg string) *StatusErr

func NewUnknownErr

func NewUnknownErr() *StatusErr

func ParseStatusErrSummary

func ParseStatusErrSummary(s string) (*StatusErr, error)

func Wrap

func Wrap(err error, code int, key string, msgs ...string) *StatusErr

func (StatusErr) AppendErrorField

func (se StatusErr) AppendErrorField(in string, field string, msg string) *StatusErr

func (StatusErr) AppendErrorFields

func (se StatusErr) AppendErrorFields(errorFields ...*ErrorField) *StatusErr

func (StatusErr) AppendSource

func (se StatusErr) AppendSource(sourceName string) *StatusErr

func (StatusErr) DisableErrTalk

func (se StatusErr) DisableErrTalk() *StatusErr

func (StatusErr) EnableErrTalk

func (se StatusErr) EnableErrTalk() *StatusErr

func (*StatusErr) Error

func (se *StatusErr) Error() string

func (*StatusErr) Is

func (se *StatusErr) Is(err error) bool

func (*StatusErr) StatusCode

func (se *StatusErr) StatusCode() int

func (*StatusErr) Summary

func (se *StatusErr) Summary() string

func (StatusErr) WithDesc

func (se StatusErr) WithDesc(desc string) *StatusErr

func (StatusErr) WithID

func (se StatusErr) WithID(id string) *StatusErr

func (StatusErr) WithMsg

func (se StatusErr) WithMsg(msg string) *StatusErr

Jump to

Keyboard shortcuts

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