errors

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBadRequest

func IsBadRequest(err error) bool

IsBadRequest 检查是否为BadRequest错误

func IsInternalServer

func IsInternalServer(err error) bool

IsInternalServer 检查是否为InternalServer错误

func IsNotFound

func IsNotFound(err error) bool

IsNotFound 检查是否为NotFound错误

Types

type Error

type Error struct {
	Code     int32             `json:"code"`
	Reason   string            `json:"reason"`
	Message  string            `json:"message"`
	Metadata map[string]string `json:"metadata"`
}

Error 是Cosmos框架的错误类型

func BadRequest

func BadRequest(reason, message string) *Error

BadRequest 返回HTTP 400错误

func Conflict

func Conflict(reason, message string) *Error

Conflict 返回HTTP 409错误

func Forbidden

func Forbidden(reason, message string) *Error

Forbidden 返回HTTP 403错误

func FromError

func FromError(err error) *Error

FromError 从error中创建Error

func InternalServer

func InternalServer(reason, message string) *Error

InternalServer 返回HTTP 500错误

func New

func New(code int32, reason, message string) *Error

New 创建一个新的错误

func NotFound

func NotFound(reason, message string) *Error

NotFound 返回HTTP 404错误

func ServiceUnavailable

func ServiceUnavailable(reason, message string) *Error

ServiceUnavailable 返回HTTP 503错误

func TooManyRequests

func TooManyRequests(reason, message string) *Error

TooManyRequests 返回HTTP 429错误

func Unauthorized

func Unauthorized(reason, message string) *Error

Unauthorized 返回HTTP 401错误

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(err error) bool

Is 报告目标错误是否与此错误匹配

func (*Error) WithMessage

func (e *Error) WithMessage(message string) *Error

WithMessage 更改错误消息

func (*Error) WithMetadata

func (e *Error) WithMetadata(md map[string]string) *Error

WithMetadata 向错误添加元数据

Jump to

Keyboard shortcuts

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