errors

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComponentError

type ComponentError interface {
	Component() string
	Error() string
}

ComponentError is a simple interface used to expose the component that sent a EMFErrror

func ErrorFromComponent

func ErrorFromComponent(component string) (e ComponentError)

ErrorFromComponent is the constructor for a ComponentError

type EMFError

type EMFError interface {
	ErrorMap() (errmap map[string]interface{}, err error)
	Execute(eh *EMFErrorHandlerType) (err error)
	ErrorWrap()
	Unwrap() error
	Is() bool
	As() bool
	ToSimpleError() *SimpleErrorType
	GetStackTrace()
	TypedError
}

EMFError is the Interface which EMFErrorType implements

type EMFErrorHandler

type EMFErrorHandler interface {
	NewError(code string, data map[string]interface{}, errors ...error) error
	Logger() echo.Logger
}

EMFErrorHandler is the Interface which EMFErrorHandlerType implements

type EMFErrorHandlerType

type EMFErrorHandlerType struct {
	DebugMode   bool
	Method      string
	Path        string
	QueryString string
	Data        map[string]interface{}
	// contains filtered or unexported fields
}

EMFErrorHandlerType is the EMF Context type that will be sent to each Handler on a request

func (EMFErrorHandlerType) Logger

func (eh EMFErrorHandlerType) Logger() echo.Logger

Logger returns the embedded echo.Logger

func (*EMFErrorHandlerType) NewError

func (eh *EMFErrorHandlerType) NewError(code string, data map[string]interface{}, errors ...error) error

NewError is a method used to generate and log an EMFError message using the configured template

type EMFErrorType

type EMFErrorType struct {
	Timestamp   string
	StatusCode  int
	ErrorCode   string
	Description string
	Message     map[string]string
	Level       string
	Data        map[string]interface{}
	// contains filtered or unexported fields
}

EMFErrorType is the type of all EMFErrors handled by the EMFErrorHandler

func (*EMFErrorType) Error

func (e *EMFErrorType) Error() string

Error implements the standard error interface TODO: find a better solution for localization

func (EMFErrorType) ErrorMap

func (e EMFErrorType) ErrorMap() (errmap map[string]interface{}, err error)

ErrorMap returns a map with all EMFErrorType fields

func (EMFErrorType) ErrorType

func (e EMFErrorType) ErrorType() string

ErrorType implements the TypedError interface and returns the ErrorCode

func (*EMFErrorType) ErrorWrap

func (e *EMFErrorType) ErrorWrap()

ErrorWrap wraps the english error message with a stacktrace, and saves that to stackTrace

func (EMFErrorType) Execute

func (e EMFErrorType) Execute(eh *EMFErrorHandlerType) (err error)

Execute executes the Message Templates using the given ErrorHandler struct as input

func (EMFErrorType) GetStackTrace

func (e EMFErrorType) GetStackTrace() string

GetStackTrace returns the hidden stackTrace field, or sets it if uninitialized

func (EMFErrorType) Is

func (e EMFErrorType) Is(target error) bool

Is is a method for comparing errors. It leverages TypedErrors for loose comparisons between EMFErrors

func (EMFErrorType) IsStatusGroup

func (e EMFErrorType) IsStatusGroup(code int) (retVal bool)

IsStatusGroup returns a true if the error's status code is in the given block of 100

func (EMFErrorType) ToSimpleError

func (e EMFErrorType) ToSimpleError() (serr *SimpleErrorType)

ToSimpleError is a method to convert a EMFErrorType into a SimpleErrorType

func (EMFErrorType) Unwrap

func (e EMFErrorType) Unwrap() error

Unwrap is a standard error method for unwrapped the error contained within

type HandlerOption

type HandlerOption func(*EMFErrorHandlerType)

HandlerOption provides the client a callback that is used to dynamically specify additional EMFErrorHandler options

func WithLogger

func WithLogger(l echo.Logger) HandlerOption

WithLogger allows the caller to specify the Logger to use for an ErrorHandler

func WithTemplate

func WithTemplate(path string) HandlerOption

WithTemplate allows the caller to specify the Error Templates to use for an ErrorHandler

type ResponseCodeError

type ResponseCodeError interface {
	Code() int
	Error() string
}

ResponseCodeError is a simple interface used to expose the response code from with a EMFErrror ErrorCode

func ErrorResponseCode

func ErrorResponseCode(code int) (e ResponseCodeError)

ErrorResponseCode is the constructor for a ResponseCodeError

type SimpleErrorType

type SimpleErrorType struct {
	Error struct {
		Message   string `json:"message"`
		ErrorCode string `json:"errorCode"`
	} `json:"error"`
	StatusCode int `json:"statusCode"`
}

SimpleErrorType is the type of errors returned to clients outside of debug mode

func (SimpleErrorType) ErrorType

func (serr SimpleErrorType) ErrorType() string

ErrorType is used for loose comparison of EMFErrors with errors.Is and errors.As

func (SimpleErrorType) ToEMFError

func (serr SimpleErrorType) ToEMFError() (e *EMFErrorType)

ToEMFError is a method to convert a SimpleErrorType into a EMFErrorType

type TypedError

type TypedError interface {
	ErrorType() string
	Error() string
}

TypedError is a simple interface used to expose the ErrorCode from EMFErrors

func ErrorType

func ErrorType(code string) (e TypedError)

ErrorType is the constructor for a TypedError

Jump to

Keyboard shortcuts

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