errors

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UnknownCode is unknown code for error info.
	UnknownCode = 500
	// UnknownReason is unknown reason for error info.
	UnknownReason = ""
	// UnknownError is unknown error for error info.
	UnknownError = "UnknownError"
)

Variables

This section is empty.

Functions

func As

func As(err error, target interface{}) bool

func Code

func Code(err error) int32

Code 返回错误的 HTTP 状态码

func Is

func Is(err, target error) bool

func IsBadRequest

func IsBadRequest(err error) bool

IsBadRequest 判断错误是否为 BadRequest

func IsClientClosed added in v0.1.11

func IsClientClosed(err error) bool

IsClientClosed 判断错误是否为 ClientClosed

func IsConflict added in v0.1.11

func IsConflict(err error) bool

IsConflict 判断错误是否为 Conflict

func IsForbidden

func IsForbidden(err error) bool

IsForbidden 判断错误是否为 Forbidden

func IsGatewayTimeout added in v0.1.11

func IsGatewayTimeout(err error) bool

IsGatewayTimeout 判断错误是否为 GatewayTimeout

func IsHTTPError added in v0.1.1

func IsHTTPError(err error) bool

IsHTTPError 判断错误是否为 HTTP 错误

func IsInternalServerError

func IsInternalServerError(err error) bool

IsInternalServerError 判断错误是否为 InternalServerError

func IsMethodNotAllowed added in v0.1.11

func IsMethodNotAllowed(err error) bool

IsMethodNotAllowed 判断错误是否为 MethodNotAllowed

func IsNotFound

func IsNotFound(err error) bool

IsNotFound 判断错误是否为 NotFound

func IsServiceUnavailable added in v0.1.11

func IsServiceUnavailable(err error) bool

IsServiceUnavailable 判断错误是否为 ServiceUnavailable

func IsUnauthorized

func IsUnauthorized(err error) bool

IsUnauthorized 判断错误是否为 Unauthorized

func Reason

func Reason(err error) string

Reason 返回错误的原因

func Unwrap

func Unwrap(err error) error

Types

type HTTPError

type HTTPError struct {
	Code     int32             `json:"code,omitempty"`     // HTTP 状态码
	Reason   string            `json:"reason,omitempty"`   // 自定义错误码
	Message  string            `json:"message,omitempty"`  // 错误信息
	Metadata map[string]string `json:"metadata,omitempty"` // 附加信息
	// contains filtered or unexported fields
}

HTTPError 表示一个 HTTP 错误

func BadRequest

func BadRequest(reason, message string) *HTTPError

BadRequest 创建一个新的 BadRequest 错误

func ClientClosed added in v0.1.11

func ClientClosed(reason, message string) *HTTPError

ClientClosed 创建一个新的 ClientClosed 错误

func Conflict added in v0.1.11

func Conflict(reason, message string) *HTTPError

Conflict 创建一个新的 Conflict 错误

func Forbidden

func Forbidden(reason, message string) *HTTPError

Forbidden 创建一个新的 Forbidden 错误

func FromError added in v0.1.11

func FromError(err error) *HTTPError

FromError 从错误创建一个 HTTPError

func GatewayTimeout added in v0.1.11

func GatewayTimeout(reason, message string) *HTTPError

GatewayTimeout 创建一个新的 GatewayTimeout 错误

func InternalServerError

func InternalServerError(reason, message string) *HTTPError

InternalServerError 创建一个新的 InternalServerError 错误

func MethodNotAllowed added in v0.1.11

func MethodNotAllowed(reason, message string) *HTTPError

MethodNotAllowed 创建一个新的 MethodNotAllowed 错误

func New

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

New 创建一个新的 HTTPError

func Newf

func Newf(code int32, reason, format string, args ...any) *HTTPError

Newf 创建一个新的 HTTPError

func NotFound

func NotFound(reason, message string) *HTTPError

NotFound 创建一个新的 NotFound 错误

func ServiceUnavailable added in v0.1.11

func ServiceUnavailable(reason, message string) *HTTPError

ServiceUnavailable 创建一个新的 ServiceUnavailable 错误

func Unauthorized

func Unauthorized(reason, message string) *HTTPError

Unauthorized 创建一个新的 Unauthorized 错误

func (*HTTPError) Cause

func (e *HTTPError) Cause() error

Cause 返回错误的原因

func (*HTTPError) Clone

func (e *HTTPError) Clone() *HTTPError

func (*HTTPError) Error

func (e *HTTPError) Error() string

Error 实现 error 接口

func (*HTTPError) GetMessage added in v0.1.1

func (e *HTTPError) GetMessage() string

GetMessage 获取错误信息

func (*HTTPError) GetMetadata added in v0.1.1

func (e *HTTPError) GetMetadata() map[string]string

GetMetadata 获取附加信息

func (*HTTPError) GetReason

func (e *HTTPError) GetReason() string

Reason 返回自定义错误码

func (*HTTPError) Is

func (e *HTTPError) Is(target error) bool

func (*HTTPError) StatusCode

func (e *HTTPError) StatusCode() int32

StatusCode 返回 HTTP 状态码

func (*HTTPError) Unwrap

func (e *HTTPError) Unwrap() error

Unwrap 实现 errors.Unwrap 接口

func (*HTTPError) WithCause

func (e *HTTPError) WithCause(cause error) *HTTPError

WithCause 设置错误的原因

func (*HTTPError) WithMetadata

func (e *HTTPError) WithMetadata(metadata map[string]string) *HTTPError

WithMetadata 添加附加信息

Jump to

Keyboard shortcuts

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