Documentation
¶
Overview ¶
Package cgerrors provides a way to return detailed information for an RPC request error. The error is normally JSON encoded.
Index ¶
- func Equal(err1 error, err2 error) bool
- func Is(err, target error) bool
- func IsAlreadyExists(err error) bool
- func IsDeadlineExceeded(err error) bool
- func IsInternal(err error) bool
- func IsInvalidArgument(err error) bool
- func IsNotFound(err error) bool
- func IsPermissionDenied(err error) bool
- func IsUnauthenticated(err error) bool
- func IsUnimplemented(err error) bool
- func ToGRPCError(err error) error
- type Error
- func ErrAlreadyExists(a ...interface{}) *Error
- func ErrAlreadyExistsf(format string, a ...interface{}) *Error
- func ErrDeadlineExceeded(a ...interface{}) *Error
- func ErrDeadlineExceededf(format string, a ...interface{}) *Error
- func ErrFailedPrecondition(a ...interface{}) *Error
- func ErrFailedPreconditionf(format string, a ...interface{}) *Error
- func ErrInternal(a ...interface{}) *Error
- func ErrInternalf(format string, a ...interface{}) *Error
- func ErrInvalidArgument(a ...interface{}) *Error
- func ErrInvalidArgumentf(format string, a ...interface{}) *Error
- func ErrNotFound(a ...interface{}) *Error
- func ErrNotFoundf(format string, a ...interface{}) *Error
- func ErrPermissionDenied(a ...interface{}) *Error
- func ErrPermissionDeniedf(format string, a ...interface{}) *Error
- func ErrUnauthenticated(a ...interface{}) *Error
- func ErrUnauthenticatedf(format string, a ...interface{}) *Error
- func ErrUnavailable(a ...interface{}) *Error
- func ErrUnavailablef(format string, a ...interface{}) *Error
- func ErrUnimplemented(a ...interface{}) *Error
- func ErrUnimplementedf(format string, a ...interface{}) *Error
- func ErrUnknown(a ...interface{}) *Error
- func ErrUnknownf(format string, a ...interface{}) *Error
- func FromError(err error) *Error
- func FromString(err string) (*Error, bool)
- func New(id, detail string, code ErrorCode) *Error
- func Parse(err string) *Error
- func To(err error) *Error
- func Wrap(err error, code ErrorCode, detail string) *Error
- func Wrapf(err error, code ErrorCode, format string, args ...interface{}) *Error
- type ErrorCode
- type ErrorCoder
- type GRPCError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAlreadyExists ¶
IsAlreadyExists checks if given error means that given entity already exists.
func IsDeadlineExceeded ¶
IsDeadlineExceeded checks if given error is of type Deadline Exceeded.
func IsInternal ¶
IsInternal checks if the input is an internal error.
func IsInvalidArgument ¶
IsInvalidArgument checks if given error means that given entity already exists.
func IsNotFound ¶
IsNotFound checks if given input error is of code NotFound.
func IsPermissionDenied ¶
IsPermissionDenied checks if given error is of type PermissionDenied.
func IsUnauthenticated ¶
IsUnauthenticated checks if given error is an unauthenticated error.
func IsUnimplemented ¶ added in v0.0.5
IsUnimplemented checks if given error contains Unimplemented code.
func ToGRPCError ¶
ToGRPCError converts an error to GRPC status.Status.
Types ¶
type Error ¶
type Error struct {
ID string `json:"id,omitempty"`
Code ErrorCode `json:"code,omitempty"`
Detail string `json:"detail,omitempty"`
Process string `json:"process,omitempty"`
Meta map[string]string `json:"meta,omitempty"`
// contains filtered or unexported fields
}
Error is the error message that has id, it's code and a detail.
func ErrAlreadyExists ¶
func ErrAlreadyExists(a ...interface{}) *Error
ErrAlreadyExists generates a 409 error.
func ErrAlreadyExistsf ¶
ErrAlreadyExistsf generates formatted 409 error.
func ErrDeadlineExceeded ¶
func ErrDeadlineExceeded(a ...interface{}) *Error
ErrDeadlineExceeded generates a 408 error.
func ErrDeadlineExceededf ¶
ErrDeadlineExceededf generates formatted 408 error.
func ErrFailedPrecondition ¶ added in v0.0.21
func ErrFailedPrecondition(a ...interface{}) *Error
ErrFailedPrecondition generates a 400 error.
func ErrFailedPreconditionf ¶ added in v0.0.21
ErrFailedPreconditionf generates a 400 error.
func ErrInternalf ¶
ErrInternalf generates formatted 500 error.
func ErrInvalidArgument ¶
func ErrInvalidArgument(a ...interface{}) *Error
ErrInvalidArgument generates a 400 error.
func ErrInvalidArgumentf ¶
ErrInvalidArgumentf generates formatted 400 error.
func ErrNotFoundf ¶
ErrNotFoundf generates formatted 404 error.
func ErrPermissionDenied ¶
func ErrPermissionDenied(a ...interface{}) *Error
ErrPermissionDenied generates a 403 error.
func ErrPermissionDeniedf ¶
ErrPermissionDeniedf generates a 403 error.
func ErrUnauthenticated ¶
func ErrUnauthenticated(a ...interface{}) *Error
ErrUnauthenticated generates a 401 error.
func ErrUnauthenticatedf ¶
ErrUnauthenticatedf generates 401 error with formatted message.
func ErrUnavailable ¶ added in v0.0.25
func ErrUnavailable(a ...interface{}) *Error
ErrUnavailable generates Unavailable error.
func ErrUnavailablef ¶ added in v0.0.25
ErrUnavailablef generates Unavailable error with formatting.
func ErrUnimplemented ¶ added in v0.0.5
func ErrUnimplemented(a ...interface{}) *Error
ErrUnimplemented generates Unimplemented error.
func ErrUnimplementedf ¶ added in v0.0.5
ErrUnimplementedf generates Unimplemented error with formatting.
func ErrUnknown ¶ added in v0.0.23
func ErrUnknown(a ...interface{}) *Error
ErrUnknown generates Unknown error.
func ErrUnknownf ¶ added in v0.0.23
ErrUnknownf generates Unknown error with formatting.
func FromString ¶ added in v0.0.23
FromString parses string error into an Error structure.
func Parse ¶
Parse tries to parse a JSON string into an error. If that fails, it will set the given string as the error detail.
func To ¶
To type check if given error is of *Error type or has encoded ErrorCode in it. Otherwise creates a new error with Unknown code.
func (*Error) GRPCStatus ¶
GRPCStatus implements grpc client interface used to convert statuses.
func (*Error) Is ¶
Is implements errors.Is function interface to check if input error matches this error or the one wrapped.
func (*Error) Unwrap ¶ added in v0.0.25
Unwrap implements errors.Unwrap function internal interface.
func (*Error) WithProcess ¶
WithProcess sets the process for given error.
type ErrorCode ¶
type ErrorCode int32
ErrorCode is a code that defines errors specification.
const ( ErrorCode_OK ErrorCode = 0 ErrorCode_Canceled ErrorCode = 1 ErrorCode_Unknown ErrorCode = 2 ErrorCode_InvalidArgument ErrorCode = 3 ErrorCode_DeadlineExceeded ErrorCode = 4 ErrorCode_NotFound ErrorCode = 5 ErrorCode_AlreadyExists ErrorCode = 6 ErrorCode_PermissionDenied ErrorCode = 7 ErrorCode_ResourceExhausted ErrorCode = 8 ErrorCode_FailedPrecondition ErrorCode = 9 ErrorCode_Aborted ErrorCode = 10 ErrorCode_OutOfRange ErrorCode = 11 ErrorCode_Unimplemented ErrorCode = 12 ErrorCode_Internal ErrorCode = 13 ErrorCode_DataLoss ErrorCode = 15 ErrorCode_Unauthenticated ErrorCode = 16 )
ErrorCode well known codes.
func (ErrorCode) ToGRPCCode ¶
ToGRPCCode gets the related grpc code.
type ErrorCoder ¶
ErrorCoder is an interface used to obtain an error code from given error within given implementation.