status

package
v0.260.3 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package status provides utilities for status and errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownstreamError

func DownstreamError(err error) error

DownstreamError creates a new error with status SourceDownstream.

func DownstreamErrorf

func DownstreamErrorf(format string, a ...any) error

DownstreamErrorf creates a new error with status SourceDownstream and formats according to a format specifier and returns the string as a value that satisfies error.

func InitSource

func InitSource(ctx context.Context) context.Context

InitSource initialize the source for the context.

func IsCancelledError

func IsCancelledError(err error) bool

InCancelledError returns true if err is context.Canceled or is gRPC status Canceled.

func IsDownstreamError

func IsDownstreamError(err error) bool

IsDownstreamError return true if provided error is an error with downstream source or a timeout error or a cancelled error.

func IsDownstreamHTTPError

func IsDownstreamHTTPError(err error) bool

IsDownstreamHTTPError return true if provided error is an error with downstream source or a HTTP timeout error or a cancelled error or a connection reset/refused error or dns not found error.

func PluginError added in v0.260.0

func PluginError(err error) error

DownstreamError creates a new error with status SourcePlugin.

func WithDownstreamSource

func WithDownstreamSource(ctx context.Context) error

WithDownstreamSource mutates the provided context by setting the source to SourceDownstream. If the provided context does not have a source, the context will not be mutated and an error returned. This means that InitSource has to be called before this function.

func WithSource

func WithSource(ctx context.Context, s Source) error

WithSource mutates the provided context by setting the source to s. If the provided context does not have a source, the context will not be mutated and an error returned. This means that InitSource has to be called before this function.

Types

type ErrorWithSource added in v0.260.0

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

func NewErrorWithSource added in v0.260.0

func NewErrorWithSource(err error, source Source) ErrorWithSource

func (ErrorWithSource) Error added in v0.260.0

func (e ErrorWithSource) Error() string

func (ErrorWithSource) ErrorSource added in v0.260.0

func (e ErrorWithSource) ErrorSource() Source

func (ErrorWithSource) Is added in v0.260.0

func (e ErrorWithSource) Is(err error) bool

Implements the interface used by errors.Is.

func (ErrorWithSource) Source added in v0.260.0

func (e ErrorWithSource) Source() Source

@deprecated Use [ErrorSource] instead.

func (ErrorWithSource) Unwrap added in v0.260.0

func (e ErrorWithSource) Unwrap() error

type Source

type Source string

Source type defines the status source.

const (
	// SourcePlugin status originates from plugin.
	SourcePlugin Source = "plugin"

	// SourceDownstream status originates from downstream service.
	SourceDownstream Source = "downstream"

	// DefaultSource is the default [Source] that should be used when it is not explicitly set.
	DefaultSource Source = SourcePlugin
)

func SourceFromContext

func SourceFromContext(ctx context.Context) Source

SourceFromContext returns the source stored in the context. If no source is stored in the context, DefaultSource is returned.

func SourceFromHTTPStatus

func SourceFromHTTPStatus(statusCode int) Source

ErrorSourceFromStatus returns a Source based on provided HTTP status code.

func (Source) IsValid

func (s Source) IsValid() bool

IsValid return true if es is SourceDownstream or SourcePlugin.

func (Source) String

func (s Source) String() string

String returns the string representation of s. If s is not valid, DefaultSource is returned.

Jump to

Keyboard shortcuts

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