ierrors

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasCode

func HasCode(target error, code InsprErrorCode) bool

HasCode checks if an error is an InsprError and if it is,

checks if it has the error code given

func IsIerror

func IsIerror(target error) bool

IsIerror checks if an error is an InsprError and if it is,

checks if it has any type of error

func Unwrap

func Unwrap(err error) error

Unwrap is a ierror function that is capable of handling both the standard golang error as well as the insprError structure, it removes the last wrap done to the err stack and if that was the last error in the stack it will return nil.

Types

type ErrBuilder

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

ErrBuilder is an Inspr Error Creator

func NewError

func NewError() *ErrBuilder

NewError is the start function to create a New Error

func (*ErrBuilder) AlreadyExists

func (b *ErrBuilder) AlreadyExists() *ErrBuilder

AlreadyExists adds Already Exists code to Inspr Error

func (*ErrBuilder) BadRequest

func (b *ErrBuilder) BadRequest() *ErrBuilder

BadRequest adds Bad Request code to Inspr Error

func (*ErrBuilder) Build

func (b *ErrBuilder) Build() *InsprError

Build returns the created Inspr Error

func (*ErrBuilder) Forbidden

func (b *ErrBuilder) Forbidden() *ErrBuilder

Forbidden adds Forbidden code to Inspr Error

func (*ErrBuilder) InnerError

func (b *ErrBuilder) InnerError(err error) *ErrBuilder

InnerError adds a inner error to the error

func (*ErrBuilder) InternalServer

func (b *ErrBuilder) InternalServer() *ErrBuilder

InternalServer adds Internal Server code to Inspr Error

func (*ErrBuilder) InvalidApp

func (b *ErrBuilder) InvalidApp() *ErrBuilder

InvalidApp adds Invalid App code to Inspr Error

func (*ErrBuilder) InvalidArgs

func (b *ErrBuilder) InvalidArgs() *ErrBuilder

InvalidArgs adds Invalid Args code to Inspr Error

func (*ErrBuilder) InvalidChannel

func (b *ErrBuilder) InvalidChannel() *ErrBuilder

InvalidChannel adds Invalid Channel code to Inspr Error

func (*ErrBuilder) InvalidFile

func (b *ErrBuilder) InvalidFile() *ErrBuilder

InvalidFile adds Invalid Args code to Inspr Error

func (*ErrBuilder) InvalidName

func (b *ErrBuilder) InvalidName() *ErrBuilder

InvalidName adds Invalid Name code to Inspr Error

func (*ErrBuilder) InvalidType

func (b *ErrBuilder) InvalidType() *ErrBuilder

InvalidType adds Invalid Type code to Inspr Error

func (*ErrBuilder) Message

func (b *ErrBuilder) Message(format string, values ...interface{}) *ErrBuilder

Message adds a message to the error

func (*ErrBuilder) NotFound

func (b *ErrBuilder) NotFound() *ErrBuilder

NotFound adds Not Found code to Inspr Error

func (*ErrBuilder) Unauthorized

func (b *ErrBuilder) Unauthorized() *ErrBuilder

Unauthorized adds Unauthorized code to Inspr Error

type InsprError

type InsprError struct {
	Message string         `yaml:"message"  json:"message"`
	Err     error          `yaml:"_" json:"_"`
	Stack   string         `yaml:"stack" json:"stack"`
	Code    InsprErrorCode `yaml:"code"  json:"code"`
}

InsprError is an error that happened inside inspr

func (*InsprError) Error

func (ierror *InsprError) Error() string

Error returns the InsprError Message

func (*InsprError) HasCode

func (ierror *InsprError) HasCode(code InsprErrorCode) bool

HasCode Compares error with error code

func (*InsprError) Is

func (ierror *InsprError) Is(target error) bool

Is Compares errors

func (*InsprError) MarshalJSON

func (ierror *InsprError) MarshalJSON() ([]byte, error)

MarshalJSON a struct function that allows for operations to be done before or after the json.Marshal procedure

func (*InsprError) StackToError

func (ierror *InsprError) StackToError()

StackToError converts the following structure of a error stack message into an actual stack of errors using the fmt.Errorf

func (*InsprError) UnmarshalJSON

func (ierror *InsprError) UnmarshalJSON(data []byte) error

UnmarshalJSON a struct function that allows for operations to be done before or after the json.Unmarshal procedure

func (*InsprError) Wrap

func (ierror *InsprError) Wrap(message string)

Wrap adds a message to the ierror stack

func (*InsprError) Wrapf

func (ierror *InsprError) Wrapf(format string, values ...interface{})

Wrapf adds the format with the values given to the ierror stack

type InsprErrorCode

type InsprErrorCode int32

InsprErrorCode is error codes for inspr errors

const (
	NotFound InsprErrorCode = 1 << iota
	AlreadyExists
	InternalServer
	InvalidName
	InvalidApp
	InvalidChannel
	InvalidType
	InvalidFile
	InvalidArgs
	BadRequest
	InvalidToken
	ExpiredToken
	Unauthorized
	Forbidden
)

Error codes for inspr errors

type MultiError

type MultiError struct {
	Errors []error
	Code   InsprErrorCode
}

MultiError is a type that handles multiple errors that can happen in a process

func (*MultiError) Add

func (e *MultiError) Add(err error)

Add adds an error to the multi error

func (*MultiError) Empty

func (e *MultiError) Empty() bool

Empty returns if there is no error in the multierror

func (*MultiError) Error

func (e *MultiError) Error() (ret string)

Error return the errors in the multierror concatenated with new lines

Jump to

Keyboard shortcuts

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