errors

package
v0.1.10 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

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 IsForbidden

func IsForbidden(err error) bool

IsForbidden 判断错误是否为 Forbidden

func IsHTTPError added in v0.1.1

func IsHTTPError(err error) bool

IsHTTPError 判断错误是否为 HTTP 错误

func IsInternalServerError

func IsInternalServerError(err error) bool

IsInternalServerError 判断错误是否为 InternalServerError

func IsNotFound

func IsNotFound(err error) bool

IsNotFound 判断错误是否为 NotFound

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 Forbidden

func Forbidden(reason, message string) *HTTPError

Forbidden 创建一个新的 Forbidden 错误

func InternalServerError

func InternalServerError(reason, message string) *HTTPError

InternalServerError 创建一个新的 InternalServerError 错误

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