errors

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const MaxCode = 1000

MaxCode [0,1000]为系统错误, 业务错误code都大于1000

Variables

View Source
var (
	// optional int32 code = 100000;
	E_Code = &file_errors_errors_proto_extTypes[0]
)

Extension fields to descriptorpb.EnumValueOptions.

View Source
var File_errors_errors_proto protoreflect.FileDescriptor

Functions

func Aborted

func Aborted(err *Error) error

Aborted The operation was aborted, typically due to a concurrency issue such as a sequencer check failure or transaction abort. HTTP Mapping: 409 Conflict

func AlreadyExists

func AlreadyExists(err *Error) error

AlreadyExists The entity that a client attempted to create (e.g., file or directory) already exists. HTTP Mapping: 409 Conflict

func BadRequest

func BadRequest(err *Error) error

BadRequest generates a 400 error.

func Cancelled

func Cancelled(err *Error) error

Cancelled The operation was cancelled, typically by the caller. HTTP Mapping: 499 Srv Closed Request

func Code

func Code(err error) int32

Code returns the status code.

func Conflict

func Conflict(err *Error) error

Conflict generates a 409 error.

func Convert added in v0.1.16

func Convert(err error) *status.Status

Convert 内部转换,为了让err=nil的时候,监控数据里有OK信息

func DataLoss

func DataLoss(err *Error) error

DataLoss Unrecoverable data loss or corruption. HTTP Mapping: 500 Internal Grpc Error

func DeadlineExceeded

func DeadlineExceeded(err *Error) error

DeadlineExceeded The deadline expired before the operation could complete. HTTP Mapping: 504 Gateway Timeout

func Err2GrpcCode

func Err2GrpcCode(err error) codes.Code

Err2GrpcCode converts a standard Go error into its canonical code. Note that this is only used to translate the error returned by the server applications.

func FailedPrecondition

func FailedPrecondition(err *Error) error

FailedPrecondition The operation was rejected because the system is not in a state required for the operation's execution. HTTP Mapping: 400 Bad Request

func Forbidden

func Forbidden(err *Error) error

Forbidden generates a 403 error.

func GrpcToHTTPStatusCode added in v0.1.16

func GrpcToHTTPStatusCode(statusCode codes.Code) int

GrpcToHTTPStatusCode gRPC转HTTP Code example:

spbStatus := status.FromContextError(err)
httpStatusCode := ecode.GrpcToHTTPStatusCode(spbStatus.Code())

func Http2GrpcCode

func Http2GrpcCode(code int32) codes.Code

func Internal

func Internal(err *Error) error

Internal This means that some invariants expected by the underlying system have been broken. This error code is reserved for serious errors.

HTTP Mapping: 500 Internal Grpc Error

func InternalServerError

func InternalServerError(err *Error) error

InternalServerError generates a 500 error.

func InvalidArgument

func InvalidArgument(err *Error) error

InvalidArgument The client specified an invalid argument. HTTP Mapping: 400 Bad Request

func IsAborted

func IsAborted(err error) bool

IsAborted determines if err is an error which indicates an aborted error. It supports wrapped errors.

func IsAlreadyExists

func IsAlreadyExists(err error) bool

IsAlreadyExists determines if err is an error which indicates a already exsits error. It supports wrapped errors.

func IsBisErr added in v0.2.0

func IsBisErr(err error) bool

IsBisErr Business error

func IsCancelled

func IsCancelled(err error) bool

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

func IsDataLoss

func IsDataLoss(err error) bool

IsDataLoss determines if err is an error which indicates a data loss error. It supports wrapped errors.

func IsDeadlineExceeded

func IsDeadlineExceeded(err error) bool

IsDeadlineExceeded determines if err is an error which indicates a deadline exceeded error. It supports wrapped errors.

func IsFailedPrecondition

func IsFailedPrecondition(err error) bool

IsFailedPrecondition determines if err is an error which indicates a failed precondition error. It supports wrapped errors.

func IsGrpcAcceptable

func IsGrpcAcceptable(err error) bool

func IsInternal

func IsInternal(err error) bool

IsInternal determines if err is an error which indicates an internal server error. It supports wrapped errors.

func IsInvalidArgument

func IsInvalidArgument(err error) bool

IsInvalidArgument determines if err is an error which indicates an invalid argument error. It supports wrapped errors.

func IsMemoryErr

func IsMemoryErr(err error) bool

func IsNotFound

func IsNotFound(err error) bool

IsNotFound determines if err is an error which indicates a not found error. It supports wrapped errors.

func IsOutOfRange

func IsOutOfRange(err error) bool

IsOutOfRange determines if err is an error which indicates a out of range error. It supports wrapped errors.

func IsPermissionDenied

func IsPermissionDenied(err error) bool

IsPermissionDenied determines if err is an error which indicates a permission denied error. It supports wrapped errors.

func IsResourceExhausted

func IsResourceExhausted(err error) bool

IsResourceExhausted determines if err is an error which indicates a resource exhausted error. It supports wrapped errors.

func IsUnauthorized

func IsUnauthorized(err error) bool

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

func IsUnavailable

func IsUnavailable(err error) bool

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

func IsUnimplemented

func IsUnimplemented(err error) bool

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

func IsUnknown

func IsUnknown(err error) bool

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

func NotFound

func NotFound(err *Error) error

NotFound generates a 404 error.

func OutOfRange

func OutOfRange(err *Error) error

OutOfRange The operation was attempted past the valid range. E.g., seeking or reading past end-of-file. HTTP Mapping: 400 Bad Request

func PermissionDenied

func PermissionDenied(err *Error) error

PermissionDenied The caller does not have permission to execute the specified operation. HTTP Mapping: 403 Forbidden

func ResourceExhausted

func ResourceExhausted(err *Error) error

ResourceExhausted Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. HTTP Mapping: 429 Too Many Requests

func Timeout

func Timeout(err *Error) error

Timeout generates a 408 error.

func Unauthorized

func Unauthorized(err *Error) error

Unauthorized generates a 401 error.

func Unavailable

func Unavailable(err *Error) error

Unavailable The service is currently unavailable. HTTP Mapping: 503 Service Unavailable

func Unimplemented

func Unimplemented(err *Error) error

Unimplemented The operation is not implemented or is not supported/enabled in this service. HTTP Mapping: 501 Not Implemented

func Unknown

func Unknown(err *Error) error

Unknown error. HTTP Mapping: 500 Internal Grpc Error

Types

type Error

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

func FromError

func FromError(err error) *Error

FromError try to convert an error to *Error. It supports wrapped errors.

func New

func New(reason string, msg string, args ...interface{}) *Error

New generates a custom error.

func Wrap added in v0.2.6

func Wrap(err error) *Error

func (*Error) AppendMetadata added in v0.2.6

func (x *Error) AppendMetadata(m map[string]string) *Error

func (*Error) As

func (x *Error) As(target interface{}) bool

func (*Error) Descriptor deprecated

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

Deprecated: Use Error.ProtoReflect.Descriptor instead.

func (*Error) Error

func (x *Error) Error() string

func (*Error) GRPCStatus added in v0.1.16

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

GRPCStatus 实现grpc status的GRPCStatus接口

func (*Error) GetCode

func (x *Error) GetCode() int32

func (*Error) GetMessage added in v0.1.16

func (x *Error) GetMessage() string

func (*Error) GetMetadata added in v0.1.16

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

func (*Error) GetReason added in v0.1.16

func (x *Error) GetReason() string

func (*Error) HTTPStatus

func (x *Error) HTTPStatus() int

HTTPStatus returns the Status represented by se.

func (*Error) Is

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

Is matches each error in the chain with the target value.

func (*Error) ProtoMessage

func (*Error) ProtoMessage()

func (*Error) ProtoReflect

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

func (*Error) Reset

func (x *Error) Reset()

func (*Error) String

func (x *Error) String() string

func (*Error) WithMetadata added in v0.1.16

func (x *Error) WithMetadata(m map[string]string) *Error

WithMetadata with an MD formed by the mapping of key, value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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