statusx

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: MIT Imports: 8 Imported by: 0

README

statusx

a enhanced http status

codecov Go Report Card Go Reference

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Is

func Is(err error) bool

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) String

func (fs ErrorFields) String() string

type ServiceCode

type ServiceCode interface {
	ServiceCode() int
}

type StatusErr

type StatusErr struct {
	Key       string      `json:"key"       xml:"key"`
	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
}

func As

func As(err error) *StatusErr

func NewStatusErr

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

func ParseSummary

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

func UnknownErr

func UnknownErr(err error) *StatusErr

func Wrap

func Wrap(err error, code int, key string, message ...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(source 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) Unwrap

func (se *StatusErr) Unwrap() error

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