statuserror

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 9 Imported by: 5

README

StatusError

GoDoc Widget Build Status codecov Go Report Card

status error for http

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func StatusCodeFromCode

func StatusCodeFromCode(code int) int

Types

type ErrorField

type ErrorField struct {
	// field path
	// prop.slice[2].a
	Field string `json:"field" xml:"field"`
	// msg
	Msg string `json:"msg" xml:"msg"`
	// location
	// eq. 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) String

func (fields ErrorFields) String() string

func (ErrorFields) Swap

func (fields ErrorFields) Swap(i, j int)

type StatusErr

type StatusErr struct {
	// key of err
	Key string `json:"key" xml:"key"`
	// http code
	Code int `json:"code" xml:"code"`
	// msg of err
	Msg string `json:"msg" xml:"msg"`
	// desc of err
	Desc string `json:"desc" xml:"desc"`
	// can be task error
	// for client to should error msg to end user
	CanBeTalkError bool `json:"canBeTalkError" xml:"canBeTalkError"`

	// request ID or other request context
	ID string `json:"id" xml:"id"`
	// error tracing
	Sources []string `json:"sources" xml:"sources"`
	// error in where fields
	ErrorFields ErrorFields `json:"errorFields" xml:"errorFields"`
	// contains filtered or unexported fields
}
Example
fmt.Println(examples.Unauthorized)
fmt.Println(statuserror.FromErr(nil))
fmt.Println(statuserror.FromErr(fmt.Errorf("unknown")))
Output:

[]@StatusErr[Unauthorized][401999001][Unauthorized]!
<nil>
[]@StatusErr[UnknownError][500000000][unknown error] unknown

func FromErr

func FromErr(err error) *StatusErr

func IsStatusErr

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

func ParseStatusErrSummary

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

func Wrap

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

func (StatusErr) AppendErrorField

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

func (StatusErr) AppendErrorFields

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

func (StatusErr) AppendSource

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

func (StatusErr) DisableErrTalk

func (statusErr StatusErr) DisableErrTalk() *StatusErr

func (StatusErr) EnableErrTalk

func (statusErr StatusErr) EnableErrTalk() *StatusErr

func (*StatusErr) Error

func (statusErr *StatusErr) Error() string

func (*StatusErr) Format

func (statusErr *StatusErr) Format(s fmt.State, verb rune)

func (*StatusErr) Is

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

func (*StatusErr) StatusCode

func (statusErr *StatusErr) StatusCode() int

func (*StatusErr) Summary

func (statusErr *StatusErr) Summary() string

func (*StatusErr) Unwrap

func (statusErr *StatusErr) Unwrap() error

func (StatusErr) WithDesc

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

func (StatusErr) WithID

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

func (StatusErr) WithMsg

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

type StatusError

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

type StatusErrorWithServiceCode

type StatusErrorWithServiceCode interface {
	ServiceCode() int
}

type WithStackTrace

type WithStackTrace interface {
	StackTrace() errors.StackTrace
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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