errors

package
v0.0.0-...-531b5da Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServiceError

func NewServiceError(code ErrorCode, msg string) error

func NewServiceErrorf

func NewServiceErrorf(code ErrorCode, msg string, args ...interface{}) error

func WrapServiceError

func WrapServiceError(code ErrorCode, msg string, wrapped error) error

Types

type ErrorCode

type ErrorCode int32
const (
	ErrCodeUnknown ErrorCode = iota

	ErrCodeService
	ErrCodeExtService

	ErrCodeNotFound
	ErrCodeAlreadyExists

	ErrCodeForbidden
	ErrCodeUnauthorised

	ErrCodeInvalidArgument
)

func (ErrorCode) GRPCCode

func (c ErrorCode) GRPCCode() codes.Code

Maps the custom service error codes to their gRPC status code equivalents.

type ServiceError

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

func (ServiceError) Code

func (e ServiceError) Code() ErrorCode

func (ServiceError) Error

func (e ServiceError) Error() string

func (ServiceError) GRPCStatus

func (e ServiceError) GRPCStatus() *status.Status

Set the gRPC status to only expose the top error message.

This is to prevent any full error contexts (from wrapped errors) being exposed to users by the gateway. e.g. "{"code":2,"message":"something went wrong scanning order: failed to connect to `host=postgres user=postgres database=postgres`: hostname resolving error (lookup postgres on 127.0.0.11:53: server misbehaving)","details":[]}"

func (ServiceError) Unwrap

func (e ServiceError) Unwrap() error

Jump to

Keyboard shortcuts

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