errx

package
v0.0.0-...-087ca59 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DataNotFoundError = errors.New("data not found")
)
View Source
var ErrPageNotFound = &HttpError{
	HttpStatus: http.StatusNotFound,
	Code:       ErrCodePageNotFound,
	Message:    "page not found",
}
View Source
var ErrUnAuthenticated = &HttpError{
	Message:    "user not login",
	Code:       ErrCodeUnAuthenticated,
	HttpStatus: http.StatusUnauthorized,
}
View Source
var ErrUnauthorized = &HttpError{
	Message:    "permission forbidden",
	Code:       ErrCodeUnauthorized,
	HttpStatus: http.StatusUnauthorized,
}
View Source
var UnhandledError = &HttpError{
	Message:    "服务器未处理异常",
	Code:       ErrCodeUnknown,
	HttpStatus: http.StatusInternalServerError,
}

Functions

func CatchPanic

func CatchPanic(message string)

func CheckError

func CheckError(err error)

func HttpPanic

func HttpPanic(code ErrCode, message string)

func NotEmpty

func NotEmpty(source string, parameter string)

func NotNil

func NotNil(source interface{}, parameter string)

func Panic

func Panic(errStr string)

func PanicEntityNotFound

func PanicEntityNotFound(message string)

func PanicErr

func PanicErr(status int, code ErrCode, message string)

func PanicNotFound

func PanicNotFound(message string)

func PanicUnAuthenticated

func PanicUnAuthenticated(message string)

func PanicUnAuthorized

func PanicUnAuthorized(message string)

func PanicValidatition

func PanicValidatition(message string)

func PrintStack

func PrintStack() string

Types

type ErrCode

type ErrCode = string
var (

	// ErrCodeUnknown 未知错误
	ErrCodeUnknown ErrCode = "unkown"

	// ErrUnknownParameterInvalid 未知原因参数不合法
	ErrUnknownParameterInvalid ErrCode = "invalid"
)
var (
	ErrCodePageNotFound   ErrCode = "Server.PageNotFound"
	ErrCodeEntityNotFound ErrCode = "Server.EntityNotFound"

	// ErrCodeBadRequest 参数校验失败
	ErrCodeBadRequest ErrCode = "Server.BadRequest"
	// ErrCodeUnAuthenticated 未认证(登录)
	ErrCodeUnAuthenticated ErrCode = "Server.UnAuthenticated"
	ErrCodeUnauthorized    ErrCode = "Server.Unauthorized"
)

type HttpError

type HttpError struct {
	HttpStatus int     `json:"-"`
	Code       ErrCode `json:"code"`
	Message    string  `json:"message"`
	Data       any     `json:"data"`
}

func New

func New(err error) HttpError

func NewUnknownErr

func NewUnknownErr(err any) HttpError

func (*HttpError) Error

func (e *HttpError) Error() string

type MultiError

type MultiError struct {
	// contains filtered or unexported fields
}

func Errors

func Errors(message string, errs ...error) *MultiError

func (*MultiError) Add

func (e *MultiError) Add(message string, err error)

func (*MultiError) AddError

func (e *MultiError) AddError(err error)

func (*MultiError) Error

func (e *MultiError) Error() string

func (*MultiError) HasError

func (e *MultiError) HasError() bool

type ValidationError

type ValidationError struct {
	ValidationErrors []*ValidationResult
}

func (*ValidationError) Error

func (v *ValidationError) Error() string

type ValidationResult

type ValidationResult struct {
	FieldName string `json:"fieldName"`
	Message   string `json:"message"`
}

Jump to

Keyboard shortcuts

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