errors

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeInternal int32 = iota + 1
	CodeNotFound
	CodeInvalidArgument
	CodePreconditionFailed
	CodeNoPermission
)

Internal error codes.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Code          int32     `json:"code"`
	ServiceName   string    `json:"service_name,omitempty"`
	Message       string    `json:"message,omitempty"`
	Destination   string    `json:"destination,omitempty"`
	Kind          ErrorKind `json:"kind"`
	SublevelError error     `json:"details,omitempty"`
	// contains filtered or unexported fields
}

Error is the framework error type that a service handler should return to keep a standard error between services.

func (*Error) Error

func (e *Error) Error() string

func (*Error) String

func (e *Error) String() string

type ErrorKind

type ErrorKind string

ErrorKind is an error representation of a mapped error.

var (
	KindValidation   ErrorKind = "ValidationError"
	KindInternal     ErrorKind = "InternalError"
	KindNotFound     ErrorKind = "NotFoundError"
	KindPrecondition ErrorKind = "ConditionError"
	KindPermission   ErrorKind = "PermissionError"
)

type Factory

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

func NewFactory

func NewFactory(options FactoryOptions) *Factory

NewFactory creates a new Factory object.

func (*Factory) FailedPrecondition

func (f *Factory) FailedPrecondition(message string) *ServiceError

FailedPrecondition sets that the current error is related to an internal condition which wasn't satisfied.

func (*Factory) Internal

func (f *Factory) Internal(err error) *ServiceError

Internal sets that the current error is related to an internal service error.

func (*Factory) InvalidArgument

func (f *Factory) InvalidArgument(err error) *ServiceError

InvalidArgument sets that the current error is related to an argument that didn't follow validation rules.

func (*Factory) NotFound

func (f *Factory) NotFound() *ServiceError

NotFound sets that the current error is related to some data not being found, probably in the database.

func (*Factory) PermissionDenied

func (f *Factory) PermissionDenied() *ServiceError

PermissionDenied sets that the current error is related to a client trying to access a resource without having permission to do so.

type FactoryOptions

type FactoryOptions struct {
	HideMessageDetails bool
	ServiceName        string
	Logger             *logger.Logger
}

type ServiceError

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

ServiceError is a structure that holds internal error details to improve error log description for the end-user, and it implements the errorApi.Error interface.

func (*ServiceError) Submit

func (s *ServiceError) Submit(ctx context.Context) error

func (*ServiceError) WithAttributes

func (s *ServiceError) WithAttributes(attrs ...logger.Attribute) *ServiceError

func (*ServiceError) WithCode

func (s *ServiceError) WithCode(code int32) *ServiceError

Jump to

Keyboard shortcuts

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