errors

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code added in v0.5.0

type Code interface {
	ErrorCode() int32
}

Code is an interface that allows a service embed an integer value into an error.

type Error

type Error interface {
	// WithCode sets a custom error code to be added inside the error.
	WithCode(code Code) Error

	// WithAttributes adds a set o custom log attributes to be inserted into
	// the log message.
	WithAttributes(attrs ...logger.Attribute) Error

	// Submit wraps the service error into a proper error type allowing the
	// service to return it.
	Submit(ctx context.Context) error

	// Kind returns the kind of error represented by the error.
	Kind() Kind
}

Error is the proper error that a service can return by its handlers. When submitted, it writes a log message describing what happened, and it gives the error using the language error type.

type ErrorFactory

type ErrorFactory interface {
	// RPC should be used when an error was received from an RPC call.
	RPC(err error, destination string) Error

	// InvalidArgument should be used when invalid arguments were received
	// inside a service handler.
	InvalidArgument(err error) Error

	// FailedPrecondition should be used when a specific condition is not met.
	FailedPrecondition(message string) Error

	// NotFound should be used when a resource was not found.
	NotFound() Error

	// Internal should be used when an unexpected behavior (or error) occurred
	// internally.
	Internal(err error) Error

	// PermissionDenied should be used when a client does not have access to
	// a specific resource.
	PermissionDenied() Error

	// Custom should be used by a service when none of the previous APIs are
	// able to handle the error that occurred. It will be forward as an internal
	// error.
	Custom(msg string) Error
}

ErrorFactory is an API that a service must use to wrap its errors into a proper framework error.

type Kind added in v0.6.0

type Kind string

Kind is an error representation of a mapped error.

var (
	KindValidation   Kind = "ValidationError"
	KindInternal     Kind = "InternalError"
	KindNotFound     Kind = "NotFoundError"
	KindPrecondition Kind = "ConditionError"
	KindPermission   Kind = "PermissionError"
	KindRPC          Kind = "RPCError"
	KindCustom       Kind = "CustomError"
)

func (Kind) String added in v0.6.0

func (k Kind) String() string

Jump to

Keyboard shortcuts

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