Documentation ¶
Index ¶
- func IsDeadlineExceeded(err error) bool
- func IsErrorAlreadyExists(err error) bool
- func IsErrorInvalidArgument(err error) bool
- func IsInternal(err error) bool
- func IsNotFound(err error) bool
- func IsPermissionDenied(err error) bool
- func IsPreconditionFailed(err error) bool
- func IsResourceExhausted(err error) bool
- func IsUnauthenticated(err error) bool
- func IsUnavailable(err error) bool
- func IsUnimplemented(err error) bool
- func IsUnknown(err error) bool
- func IsXError(err error) bool
- func ThrowAlreadyExists(cause error, reason, message string) error
- func ThrowAlreadyExistsF(cause error, reason, format string, a ...interface{}) error
- func ThrowDeadlineExceeded(cause error, reason, message string) error
- func ThrowDeadlineExceededF(cause error, reason, format string, a ...interface{}) error
- func ThrowInternal(cause error, reason, message string) error
- func ThrowInternalF(cause error, reason, format string, a ...interface{}) error
- func ThrowInvalidArgument(cause error, reason, message string) error
- func ThrowInvalidArgumentF(cause error, reason, format string, a ...interface{}) error
- func ThrowNotFound(cause error, reason, message string) error
- func ThrowNotFoundF(cause error, reason, format string, a ...interface{}) error
- func ThrowPermissionDenied(cause error, reason, message string) error
- func ThrowPermissionDeniedF(cause error, reason, format string, a ...interface{}) error
- func ThrowPreconditionFailed(cause error, reason, message string) error
- func ThrowPreconditionFailedF(cause error, reason, format string, a ...interface{}) error
- func ThrowResourceExhausted(cause error, reason, message string) error
- func ThrowResourceExhaustedF(cause error, reason, format string, a ...interface{}) error
- func ThrowUnauthenticated(cause error, reason, message string) error
- func ThrowUnauthenticatedF(cause error, reason, format string, a ...interface{}) error
- func ThrowUnavailable(cause error, reason, message string) error
- func ThrowUnavailableF(cause error, reason, format string, a ...interface{}) error
- func ThrowUnimplemented(cause error, reason, message string) error
- func ThrowUnimplementedF(cause error, reason, format string, a ...interface{}) error
- func ThrowUnknown(cause error, reason, message string) error
- func ThrowUnknownF(cause error, reason, format string, a ...interface{}) error
- type AlreadyExists
- type AlreadyExistsError
- type DeadlineExceeded
- type DeadlineExceededError
- type Error
- type Internal
- type InternalError
- type InvalidArgument
- type InvalidArgumentError
- type NotFound
- type NotFoundError
- type PermissionDenied
- type PermissionDeniedError
- type PreconditionFailed
- type PreconditionFailedError
- type ResourceExhausted
- type ResourceExhaustedError
- type Unauthenticated
- type UnauthenticatedError
- type Unavailable
- type UnavailableError
- type Unimplemented
- type UnimplementedError
- type Unknown
- type UnknownError
- type XError
- func (e *XError) As(target interface{}) bool
- func (e *XError) Cause() error
- func (e *XError) Details() map[string]interface{}
- func (e *XError) Error() string
- func (e *XError) Is(target error) bool
- func (e *XError) Message() string
- func (e *XError) Reason() string
- func (e *XError) Unwrap() error
- func (e *XError) WithDetails(details map[string]interface{})
- func (e *XError) WithMessage(message string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsDeadlineExceeded ¶
func IsErrorAlreadyExists ¶
func IsErrorInvalidArgument ¶
func IsInternal ¶
func IsNotFound ¶
func IsPermissionDenied ¶
func IsPreconditionFailed ¶
func IsResourceExhausted ¶
func IsUnauthenticated ¶
func IsUnavailable ¶
func IsUnimplemented ¶
func ThrowAlreadyExists ¶
func ThrowAlreadyExistsF ¶
func ThrowDeadlineExceeded ¶
func ThrowDeadlineExceededF ¶
func ThrowInternal ¶
func ThrowInternalF ¶
func ThrowInvalidArgument ¶
func ThrowInvalidArgumentF ¶
func ThrowNotFound ¶
func ThrowNotFoundF ¶
func ThrowPermissionDenied ¶
func ThrowPermissionDeniedF ¶
func ThrowPreconditionFailed ¶
func ThrowResourceExhausted ¶
func ThrowResourceExhaustedF ¶
func ThrowUnauthenticated ¶
func ThrowUnauthenticatedF ¶
func ThrowUnavailable ¶
func ThrowUnavailableF ¶
func ThrowUnimplemented ¶
func ThrowUnimplementedF ¶
func ThrowUnknown ¶
func ThrowUnknownF ¶
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 }
Unavailable 是不可用错误 对应于 HTTP 状态码 503 例如:服务不可用,资源不可用等
type UnavailableError ¶
type UnavailableError struct {
}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
}