errors

package
v0.0.0-...-0b0e567 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package errors provides a way to return detailed information for an RPC request error. The error is normally JSON encoded.

Index

Constants

This section is empty.

Variables

View Source
var File_errors_errors_proto protoreflect.FileDescriptor

Functions

func AsRetryable

func AsRetryable(err error) error

AsRetryable wraps an error and marks it as retryable. Returns nil if the input error is nil.

func BadRequest

func BadRequest(id, format string, a ...any) error

BadRequest generates a 400 error.

func Conflict

func Conflict(id, format string, a ...any) error

Conflict generates a 409 error.

func Equal

func Equal(err1 error, err2 error) bool

Equal tries to compare errors.

func Forbidden

func Forbidden(id, format string, a ...any) error

Forbidden generates a 403 error.

func HasCode

func HasCode(err error, code int32) bool

HasCode traverses the entire error chain and checks if any *Error has the given code.

func InternalServerError

func InternalServerError(id, format string, a ...any) error

InternalServerError generates a 500 error.

func IsBadRequest

func IsBadRequest(err error) bool

IsBadRequest checks if the error is a bad request error (400).

func IsConflict

func IsConflict(err error) bool

IsConflict checks if the error is a conflict error (409).

func IsForbidden

func IsForbidden(err error) bool

IsForbidden checks if the error is a forbidden error (403).

func IsInternalServerError

func IsInternalServerError(err error) bool

IsInternalServerError checks if the error is an internal server error (500).

func IsNotFound

func IsNotFound(err error) bool

IsNotFound checks if the error is a not found error (404).

func IsRetryable

func IsRetryable(err error) bool

IsRetryable checks if an error is retryable. By default, Timeout(408), TooManyRequests(429), and ServiceUnavailable(503) are retryable.

func IsServiceUnavailable

func IsServiceUnavailable(err error) bool

IsServiceUnavailable checks if the error is a service unavailable error (503).

func IsTimeout

func IsTimeout(err error) bool

IsTimeout checks if the error is a timeout error (408).

func IsTooManyRequests

func IsTooManyRequests(err error) bool

IsTooManyRequests checks if the error is a too many requests error (429).

func IsUnauthorized

func IsUnauthorized(err error) bool

IsUnauthorized checks if the error is an unauthorized error (401).

func MethodNotAllowed

func MethodNotAllowed(id, format string, a ...any) error

MethodNotAllowed generates a 405 error.

func New

func New(id, detail string, code int32) error

New generates a custom error.

func NotFound

func NotFound(id, format string, a ...any) error

NotFound generates a 404 error.

func ServiceUnavailable

func ServiceUnavailable(id, format string, a ...any) error

ServiceUnavailable generates a 503 error (retryable by default).

func Timeout

func Timeout(id, format string, a ...any) error

Timeout generates a 408 error.

func TooManyRequests

func TooManyRequests(id, format string, a ...any) error

TooManyRequests generates a 429 error (retryable by default).

func Unauthorized

func Unauthorized(id, format string, a ...any) error

Unauthorized generates a 401 error.

func Wrap

func Wrap(err error, id string, code int32, detail string) error

Wrap wraps an existing error with microservice error context. Returns nil if the input error is nil.

func Wrapf

func Wrapf(err error, id string, code int32, format string, a ...any) error

Wrapf wraps an error with formatted detail message. Returns nil if the input error is nil.

Types

type Error

type Error struct {
	Id     string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	Code   int32  `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
	Detail string `protobuf:"bytes,3,opt,name=detail,proto3" json:"detail,omitempty"`
	Status string `protobuf:"bytes,4,opt,name=status,proto3" json:"status,omitempty"`
	// contains filtered or unexported fields
}

func As

func As(err error) (*Error, bool)

As finds the first error in err's chain that matches *Error.

func FromError

func FromError(err error) *Error

FromError try to convert go error to *Error.

func Parse

func Parse(err string) *Error

Parse tries to parse a JSON string into an error. If that fails, it will set the given string as the error detail.

func (*Error) Descriptor deprecated

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

Deprecated: Use Error.ProtoReflect.Descriptor instead.

func (*Error) Error

func (e *Error) Error() string

func (*Error) GetCode

func (x *Error) GetCode() int32

func (*Error) GetDetail

func (x *Error) GetDetail() string

func (*Error) GetId

func (x *Error) GetId() string

func (*Error) GetStatus

func (x *Error) GetStatus() string

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

type MultiError

type MultiError struct {
	Errors []*Error `protobuf:"bytes,1,rep,name=errors,proto3" json:"errors,omitempty"`
	// contains filtered or unexported fields
}

func NewMultiError

func NewMultiError() *MultiError

func (*MultiError) Append

func (e *MultiError) Append(err ...*Error)

func (*MultiError) Descriptor deprecated

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

Deprecated: Use MultiError.ProtoReflect.Descriptor instead.

func (*MultiError) Error

func (e *MultiError) Error() string

func (*MultiError) GetErrors

func (x *MultiError) GetErrors() []*Error

func (*MultiError) HasErrors

func (e *MultiError) HasErrors() bool

func (*MultiError) ProtoMessage

func (*MultiError) ProtoMessage()

func (*MultiError) ProtoReflect

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

func (*MultiError) Reset

func (x *MultiError) Reset()

func (*MultiError) String

func (x *MultiError) String() string

type RetryableError

type RetryableError struct {
	Err error
}

RetryableError wraps an error and marks it as retryable.

func (*RetryableError) Error

func (e *RetryableError) Error() string

Error returns the error message.

func (*RetryableError) Unwrap

func (e *RetryableError) Unwrap() error

Unwrap returns the underlying error.

type WrappedError

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

WrappedError supports error chain wrapping.

func (*WrappedError) As

func (e *WrappedError) As(target any) bool

As implements the interface for errors.As to find *Error.

func (*WrappedError) Error

func (e *WrappedError) Error() string

Error returns the error message.

func (*WrappedError) Unwrap

func (e *WrappedError) Unwrap() error

Unwrap returns the underlying cause error.

Source Files

  • errors.go
  • errors.pb.go
  • errors.pb.micro.go

Jump to

Keyboard shortcuts

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