errors

package
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: Apache-2.0 Imports: 10 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 = ""
)

Variables

View Source
var ErrDetails = errors.New("no error details for status with code OK")
View Source
var File_errors_proto protoreflect.FileDescriptor

Functions

func As added in v1.0.1

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

func Code added in v1.0.1

func Code(err error) int

Code 返回err指定的错误码

func Is added in v1.0.1

func Is(err, target error) bool

func IsBadRequest added in v1.0.1

func IsBadRequest(err error) bool

IsBadRequest determines if err is an error which indicates a BadRequest error. It supports wrapped errors.

func IsClientClosed added in v1.0.1

func IsClientClosed(err error) bool

IsClientClosed determines if err is an error which indicates a IsClientClosed error. It supports wrapped errors.

func IsConflict added in v1.0.1

func IsConflict(err error) bool

IsConflict determines if err is an error which indicates a Conflict error. It supports wrapped errors.

func IsForbidden added in v1.0.1

func IsForbidden(err error) bool

IsForbidden determines if err is an error which indicates a Forbidden error. It supports wrapped errors.

func IsGatewayTimeout added in v1.0.1

func IsGatewayTimeout(err error) bool

IsGatewayTimeout determines if err is an error which indicates a GatewayTimeout error. It supports wrapped errors.

func IsInternalServer added in v1.0.1

func IsInternalServer(err error) bool

IsInternalServer determines if err is an error which indicates an Internal error. It supports wrapped errors.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound determines if err is an error which indicates an NotFound error. It supports wrapped errors.

func IsServiceUnavailable added in v1.0.1

func IsServiceUnavailable(err error) bool

IsServiceUnavailable determines if err is an error which indicates a Unavailable error. It supports wrapped errors.

func IsUnauthorized added in v1.0.1

func IsUnauthorized(err error) bool

IsUnauthorized determines if err is an error which indicates a Unauthorized error. It supports wrapped errors.

func Reason added in v1.0.1

func Reason(err error) string

Reason 返回err的reason

func Unwrap added in v1.0.1

func Unwrap(err error) error

Types

type Error

type Error struct {

	// code: status code
	Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
	// reason:
	Reason string `protobuf:"bytes,2,opt,name=reason,proto3" json:"reason,omitempty"`
	// message:
	Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"`
	// metadata:
	Metadata map[string]string `` /* 157-byte string literal not displayed */
	// contains filtered or unexported fields
}

func BadRequest added in v1.0.1

func BadRequest(reason, message string) *Error

BadRequest new BadRequest error that is mapped to a 400 response.

func ClientClosed added in v1.0.1

func ClientClosed(reason, message string) *Error

ClientClosed new ClientClosed error that is mapped to a HTTP 499 response.

func Conflict added in v1.0.1

func Conflict(reason, message string) *Error

Conflict new Conflict error that is mapped to a 409 response.

func Errorf

func Errorf(code int, reason, format string, a ...interface{}) *Error

func Forbidden added in v1.0.1

func Forbidden(reason, message string) *Error

Forbidden new Forbidden error that is mapped to a 403 response.

func FromError added in v1.0.1

func FromError(err error) *Error

func GatewayTimeout added in v1.0.1

func GatewayTimeout(reason, message string) *Error

GatewayTimeout new GatewayTimeout error that is mapped to a HTTP 504 response.

func InternalServer added in v1.0.1

func InternalServer(reason, message string) *Error

InternalServer new InternalServer error that is mapped to a 500 response.

func New added in v1.0.1

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

New 实例化 Error 对象

func NotFound

func NotFound(reason, message string) *Error

NotFound new NotFound error that is mapped to a 404 response.

func ServiceUnavailable added in v1.0.1

func ServiceUnavailable(reason, message string) *Error

ServiceUnavailable new ServiceUnavailable error that is mapped to a HTTP 503 response.

func Unauthorized added in v1.0.1

func Unauthorized(reason, message string) *Error

Unauthorized new Unauthorized error that is mapped to a 401 response.

func (*Error) AddMetadata added in v1.0.1

func (x *Error) AddMetadata(mp map[string]string) *Error

AddMetadata 增加metadata

func (*Error) Descriptor deprecated added in v1.0.1

func (*Error) Descriptor() ([]byte, []int)

Deprecated: Use Error.ProtoReflect.Descriptor instead.

func (*Error) Error added in v1.0.1

func (x *Error) Error() string

Error 实现Error接口

func (*Error) GRPCStatus added in v1.0.1

func (x *Error) GRPCStatus() *status.Status

GRPCStatus 返回grpc status

func (*Error) GetCode added in v1.0.1

func (x *Error) GetCode() int32

func (*Error) GetMessage added in v1.0.1

func (x *Error) GetMessage() string

func (*Error) GetMetadata added in v1.0.1

func (x *Error) GetMetadata() map[string]string

func (*Error) GetReason added in v1.0.1

func (x *Error) GetReason() string

func (*Error) Is added in v1.0.1

func (x *Error) Is(target error) bool

Is 跟 target Error 比较 判断是否相等

func (*Error) ProtoMessage added in v1.0.1

func (*Error) ProtoMessage()

func (*Error) ProtoReflect added in v1.0.1

func (x *Error) ProtoReflect() protoreflect.Message

func (*Error) Reset added in v1.0.1

func (x *Error) Reset()

func (*Error) StatusCode added in v1.0.1

func (x *Error) StatusCode() int

StatusCode HTTP code

func (*Error) String added in v1.0.1

func (x *Error) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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