errors

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: Apache-2.0 Imports: 5 Imported by: 33

README

Errors

errors package serve to build an arbitrary long error chain in order to capture errors returned from nested service calls.

errors package contains the custom Go error interface implementation, Error. You use the Error interface to wrap two errors in a containing error as well as to test recursively if a given error contains some other error.

Documentation

Overview

Package errors contains Magistrala errors definitions.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMalformedEntity indicates a malformed entity specification.
	ErrMalformedEntity = New("malformed entity specification")

	// ErrUnsupportedContentType indicates invalid content type.
	ErrUnsupportedContentType = errors.New("invalid content type")

	// ErrUnidentified indicates unidentified error.
	ErrUnidentified = errors.New("unidentified error")

	// ErrEmptyPath indicates empty file path.
	ErrEmptyPath = errors.New("empty file path")

	// ErrStatusAlreadyAssigned indicated that the client or group has already been assigned the status.
	ErrStatusAlreadyAssigned = errors.New("status already assigned")

	// ErrRollbackTx indicates failed to rollback transaction.
	ErrRollbackTx = errors.New("failed to rollback transaction")

	// ErrAuthentication indicates failure occurred while authenticating the entity.
	ErrAuthentication = errors.New("failed to perform authentication over the entity")

	// ErrAuthorization indicates failure occurred while authorizing the entity.
	ErrAuthorization = errors.New("failed to perform authorization over the entity")
)

Functions

func Contains

func Contains(e1, e2 error) bool

Contains inspects if e2 error is contained in any layer of e1 error.

func Unwrap

func Unwrap(err error) (error, error)

Unwrap returns the wrapper and the error by separating the Wrapper from the error.

func Wrap

func Wrap(wrapper, err error) error

Wrap returns an Error that wrap err with wrapper.

Types

type Error

type Error interface {
	// Error implements the error interface.
	Error() string

	// Msg returns error message.
	Msg() string

	// Err returns wrapped error.
	Err() Error

	// MarshalJSON returns a marshaled error.
	MarshalJSON() ([]byte, error)
}

Error specifies an API that must be fullfiled by error type.

func New

func New(text string) Error

New returns an Error that formats as the given text.

type SDKError

type SDKError interface {
	Error
	StatusCode() int
}

SDKError is an error type for Magistrala SDK.

func CheckError

func CheckError(resp *http.Response, expectedStatusCodes ...int) SDKError

CheckError will check the HTTP response status code and matches it with the given status codes. Since multiple status codes can be valid, we can pass multiple status codes to the function. The function then checks for errors in the HTTP response.

func NewSDKError

func NewSDKError(err error) SDKError

NewSDKError returns an SDK Error that formats as the given text.

func NewSDKErrorWithStatus

func NewSDKErrorWithStatus(err error, statusCode int) SDKError

NewSDKErrorWithStatus returns an SDK Error setting the status code.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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