errorsext

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDeadlineExceeded

func IsDeadlineExceeded(err error) bool

func IsErrorAlreadyExists

func IsErrorAlreadyExists(err error) bool

func IsErrorInvalidArgument

func IsErrorInvalidArgument(err error) bool

func IsInternal

func IsInternal(err error) bool

func IsNotFound

func IsNotFound(err error) bool

func IsPermissionDenied

func IsPermissionDenied(err error) bool

func IsPreconditionFailed

func IsPreconditionFailed(err error) bool

func IsResourceExhausted

func IsResourceExhausted(err error) bool

func IsUnauthenticated

func IsUnauthenticated(err error) bool

func IsUnavailable

func IsUnavailable(err error) bool

func IsUnimplemented

func IsUnimplemented(err error) bool

func IsUnknown

func IsUnknown(err error) bool

func IsXError

func IsXError(err error) bool

func ThrowAlreadyExists

func ThrowAlreadyExists(cause error, reason, message string) error

func ThrowAlreadyExistsF

func ThrowAlreadyExistsF(cause error, reason, format string, a ...interface{}) error

func ThrowDeadlineExceeded

func ThrowDeadlineExceeded(cause error, reason, message string) error

func ThrowDeadlineExceededF

func ThrowDeadlineExceededF(cause error, reason, format string, a ...interface{}) error

func ThrowInternal

func ThrowInternal(cause error, reason, message string) error

func ThrowInternalF

func ThrowInternalF(cause error, reason, format string, a ...interface{}) error

func ThrowInvalidArgument

func ThrowInvalidArgument(cause error, reason, message string) error

func ThrowInvalidArgumentF

func ThrowInvalidArgumentF(cause error, reason, format string, a ...interface{}) error

func ThrowNotFound

func ThrowNotFound(cause error, reason, message string) error

func ThrowNotFoundF

func ThrowNotFoundF(cause error, reason, format string, a ...interface{}) error

func ThrowPermissionDenied

func ThrowPermissionDenied(cause error, reason, message string) error

func ThrowPermissionDeniedF

func ThrowPermissionDeniedF(cause error, reason, format string, a ...interface{}) error

func ThrowPreconditionFailed

func ThrowPreconditionFailed(cause error, reason, message string) error

func ThrowPreconditionFailedF

func ThrowPreconditionFailedF(cause error, reason, format string, a ...interface{}) error

func ThrowResourceExhausted

func ThrowResourceExhausted(cause error, reason, message string) error

func ThrowResourceExhaustedF

func ThrowResourceExhaustedF(cause error, reason, format string, a ...interface{}) error

func ThrowUnauthenticated

func ThrowUnauthenticated(cause error, reason, message string) error

func ThrowUnauthenticatedF

func ThrowUnauthenticatedF(cause error, reason, format string, a ...interface{}) error

func ThrowUnavailable

func ThrowUnavailable(cause error, reason, message string) error

func ThrowUnavailableF

func ThrowUnavailableF(cause error, reason, format string, a ...interface{}) error

func ThrowUnimplemented

func ThrowUnimplemented(cause error, reason, message string) error

func ThrowUnimplementedF

func ThrowUnimplementedF(cause error, reason, format string, a ...interface{}) error

func ThrowUnknown

func ThrowUnknown(cause error, reason, message string) error

func ThrowUnknownF

func ThrowUnknownF(cause error, reason, format string, a ...interface{}) error

Types

type AlreadyExists

type AlreadyExists interface {
	error
	IsAlreadyExists()
}

AlreadyExists 是已经存在的错误 对应状态码 409 例如:用户已经存在,数据库中已经存在等

type AlreadyExistsError

type AlreadyExistsError struct {
	*XError
}

func (*AlreadyExistsError) Cause

func (err *AlreadyExistsError) Cause() error

func (*AlreadyExistsError) Is

func (err *AlreadyExistsError) Is(target error) bool

func (*AlreadyExistsError) IsAlreadyExists

func (err *AlreadyExistsError) IsAlreadyExists()

func (*AlreadyExistsError) Unwrap

func (err *AlreadyExistsError) Unwrap() error

type DeadlineExceeded

type DeadlineExceeded interface {
	error
	IsDeadlineExceeded()
}

DeadlineExceeded 是操作超时错误。 对应 HTTP 状态码为 408。 操作超时错误,通常是因为资源被其他进程占用,或者操作本身需要很长时间。

type DeadlineExceededError

type DeadlineExceededError struct {
	*XError
}

func (*DeadlineExceededError) Cause

func (err *DeadlineExceededError) Cause() error

func (*DeadlineExceededError) Is

func (err *DeadlineExceededError) Is(target error) bool

func (*DeadlineExceededError) IsDeadlineExceeded

func (err *DeadlineExceededError) IsDeadlineExceeded()

func (*DeadlineExceededError) Unwrap

func (err *DeadlineExceededError) Unwrap() error

type Error

type Error interface {
	error
	// Cause 返回原始错误
	Cause() error
	// Unwrap 返回原始错误 兼容 Go 1.13
	Unwrap() error
	// Message 错误信息,为用户可读的信息,可作为用户提示内容
	Message() string
	WithMessage(message string)
	WithDetails(details map[string]interface{})
	// Details 错误元信息,为错误添加附加可扩展信息
	Details() map[string]interface{}
	// Reason 错误原因,定义为业务判定错误码
	Reason() string
}

Error 错误接口 inspire by https://cloud.google.com/apis/design/errors?hl=zh-cn

type Internal

type Internal interface {
	error
	IsInternal()
}

Internal 接口用于标识内部错误, 对应状态码 500 内部错误通常表示程序逻辑错误, 内部错误通常不应该被用户看到,

type InternalError

type InternalError struct {
	*XError
}

func (*InternalError) Cause

func (err *InternalError) Cause() error

func (*InternalError) Error

func (err *InternalError) Error() string

func (*InternalError) Is

func (err *InternalError) Is(target error) bool

func (*InternalError) IsInternal

func (err *InternalError) IsInternal()

func (*InternalError) Unwrap

func (err *InternalError) Unwrap() error

type InvalidArgument

type InvalidArgument interface {
	error
	IsInvalidArgument()
}

InvalidArgument 参数错误 对应 HTTP 状态码:400 Bad Request 参数错误,例如:参数为空、参数格式不正确等 请求字段 x.y.z 是 xxx,预期为 [yyy, zzz] 内的一个。

type InvalidArgumentError

type InvalidArgumentError struct {
	*XError
}

func (*InvalidArgumentError) Cause

func (err *InvalidArgumentError) Cause() error

func (*InvalidArgumentError) Is

func (err *InvalidArgumentError) Is(target error) bool

func (*InvalidArgumentError) IsInvalidArgument

func (err *InvalidArgumentError) IsInvalidArgument()

func (*InvalidArgumentError) Unwrap

func (err *InvalidArgumentError) Unwrap() error

type NotFound

type NotFound interface {
	error
	IsNotFound()
}

NotFound 是未找到的错误 对应 HTTP 状态码:404 Not Found 未找到的错误,通常表示请求的资源不存在。 例如:用户不存在,或者请求的资源不存在。

type NotFoundError

type NotFoundError struct {
	*XError
}

func (*NotFoundError) Cause

func (err *NotFoundError) Cause() error

func (*NotFoundError) Is

func (err *NotFoundError) Is(target error) bool

func (*NotFoundError) IsNotFound

func (err *NotFoundError) IsNotFound()

func (*NotFoundError) Unwrap

func (err *NotFoundError) Unwrap() error

type PermissionDenied

type PermissionDenied interface {
	error
	IsPermissionDenied()
}

PermissionDenied 是权限拒绝的错误 对应 HTTP 状态码:403

权限拒绝的错误,通常表示用户没有权限执行某些操作。

例如:

  • 用户没有权限查看某个资源
  • 用户没有权限修改某个资源
  • 用户没有权限删除某个资源

type PermissionDeniedError

type PermissionDeniedError struct {
	*XError
}

func (*PermissionDeniedError) Cause

func (err *PermissionDeniedError) Cause() error

func (*PermissionDeniedError) Is

func (err *PermissionDeniedError) Is(target error) bool

func (*PermissionDeniedError) IsPermissionDenied

func (err *PermissionDeniedError) IsPermissionDenied()

func (*PermissionDeniedError) Unwrap

func (err *PermissionDeniedError) Unwrap() error

type PreconditionFailed

type PreconditionFailed interface {
	error
	IsPreconditionFailed()
}

PreconditionFailed 是前置条件失败的错误接口 对应 HTTP 状态码 412 用于表示前置条件不满足,导致当前操作无法继续执行 例如:资源 xxx 是非空目录,因此无法删除。

type PreconditionFailedError

type PreconditionFailedError struct {
	*XError
}

func (*PreconditionFailedError) Cause

func (err *PreconditionFailedError) Cause() error

func (*PreconditionFailedError) Is

func (err *PreconditionFailedError) Is(target error) bool

func (*PreconditionFailedError) IsPreconditionFailed

func (err *PreconditionFailedError) IsPreconditionFailed()

func (*PreconditionFailedError) Unwrap

func (err *PreconditionFailedError) Unwrap() error

type ResourceExhausted

type ResourceExhausted interface {
	error
	IsResourceExhausted()
}

ResourceExhausted 是资源耗尽的错误 对应于 HTTP 状态码 429 Too Many Requests 例如:数据库连接池已满,内存不足等

type ResourceExhaustedError

type ResourceExhaustedError struct {
	*XError
}

func (*ResourceExhaustedError) Cause

func (err *ResourceExhaustedError) Cause() error

func (*ResourceExhaustedError) Is

func (err *ResourceExhaustedError) Is(target error) bool

func (*ResourceExhaustedError) IsResourceExhausted

func (err *ResourceExhaustedError) IsResourceExhausted()

func (*ResourceExhaustedError) Unwrap

func (err *ResourceExhaustedError) Unwrap() error

type Unauthenticated

type Unauthenticated interface {
	error
	IsUnauthenticated()
}

Unauthenticated 是未认证的错误。 对应于 HTTP 401 Unauthorized。 用于表示用户未登录、未授权等。

type UnauthenticatedError

type UnauthenticatedError struct {
	*XError
}

func (*UnauthenticatedError) Cause

func (err *UnauthenticatedError) Cause() error

func (*UnauthenticatedError) Is

func (err *UnauthenticatedError) Is(target error) bool

func (*UnauthenticatedError) IsUnauthenticated

func (err *UnauthenticatedError) IsUnauthenticated()

func (*UnauthenticatedError) Unwrap

func (err *UnauthenticatedError) Unwrap() error

type Unavailable

type Unavailable interface {
	error
	IsUnavailable()
}

Unavailable 是不可用错误 对应于 HTTP 状态码 503 例如:服务不可用,资源不可用等

type UnavailableError

type UnavailableError struct {
	*XError
}

func (*UnavailableError) Cause

func (err *UnavailableError) Cause() error

func (*UnavailableError) Is

func (err *UnavailableError) Is(target error) bool

func (*UnavailableError) IsUnavailable

func (err *UnavailableError) IsUnavailable()

func (*UnavailableError) Unwrap

func (err *UnavailableError) Unwrap() error

type Unimplemented

type Unimplemented interface {
	error
	IsUnimplemented()
}

Unimplemented 是未实现错误 对应状态码 501 用于表示未实现的功能,比如未实现的接口方法

type UnimplementedError

type UnimplementedError struct {
	*XError
}

func (*UnimplementedError) Cause

func (err *UnimplementedError) Cause() error

func (*UnimplementedError) Is

func (err *UnimplementedError) Is(target error) bool

func (*UnimplementedError) IsUnimplemented

func (err *UnimplementedError) IsUnimplemented()

func (*UnimplementedError) Unwrap

func (err *UnimplementedError) Unwrap() error

type Unknown

type Unknown interface {
	error
	IsUnknown()
}

Unknown 未知错误 对应Http 500 未知错误,通常用于表示无法识别的错误

type UnknownError

type UnknownError struct {
	*XError
}

func (*UnknownError) Cause

func (err *UnknownError) Cause() error

func (*UnknownError) Is

func (err *UnknownError) Is(target error) bool

func (*UnknownError) IsUnknown

func (err *UnknownError) IsUnknown()

func (*UnknownError) Unwrap

func (err *UnknownError) Unwrap() error

type XError

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

func New

func New(reason, message string) *XError

func NewF

func NewF(reason, format string, args ...interface{}) *XError

func Wrap

func Wrap(cause error, reason, message string) *XError

func WrapF

func WrapF(cause error, reason, format string, args ...interface{}) *XError

func (*XError) As

func (e *XError) As(target interface{}) bool

func (*XError) Cause

func (e *XError) Cause() error

func (*XError) Details

func (e *XError) Details() map[string]interface{}

func (*XError) Error

func (e *XError) Error() string

func (*XError) Is

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

func (*XError) Message

func (e *XError) Message() string

func (*XError) Reason

func (e *XError) Reason() string

func (*XError) Unwrap

func (e *XError) Unwrap() error

func (*XError) WithDetails

func (e *XError) WithDetails(details map[string]interface{})

func (*XError) WithMessage

func (e *XError) WithMessage(message string)

Jump to

Keyboard shortcuts

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