tiny_errors

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 5 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorStorage

func ErrorStorage() map[int]string

func Init

func Init(errors map[int]string)

Types

type Error

type Error struct {
	Code    int            `json:"code"`
	Message string         `json:"message"`
	Details map[string]any `json:"details"`
	Errors  []*MiniError   `json:"errors"`
	// contains filtered or unexported fields
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) FormatMessage

func (e *Error) FormatMessage(args ...any)

func (*Error) GetCode

func (e *Error) GetCode() int

func (*Error) GetHTTPMessage

func (e *Error) GetHTTPMessage() string

func (*Error) GetHTTPStatus

func (e *Error) GetHTTPStatus() int

func (*Error) GetMessage

func (e *Error) GetMessage() string

func (*Error) JSON

func (e *Error) JSON() string

func (*Error) JSONOrigin

func (e *Error) JSONOrigin() string

func (*Error) SetCode

func (e *Error) SetCode(code int)

func (*Error) SetDetail

func (e *Error) SetDetail(name, data string)

func (*Error) SetError

func (e *Error) SetError(err *MiniError)

func (*Error) SetHTTPStatus

func (e *Error) SetHTTPStatus(code int)

func (*Error) SetMessage

func (e *Error) SetMessage(msg string, format ...any)

type ErrorHandler

type ErrorHandler interface {
	JSON() string
	JSONOrigin() string
	Error() string

	GetHTTPStatus() int
	GetHTTPMessage() string
	GetCode() int
	GetMessage() string
}

func New

func New(code int, options ...ErrorOption) ErrorHandler

type ErrorOption

type ErrorOption func(PropertySetter)

func Detail

func Detail(name, data string) ErrorOption

func Err

func Err(miniErr *MiniError) ErrorOption

func HTTPStatus

func HTTPStatus(status int) ErrorOption

func Message

func Message(message string, format ...any) ErrorOption

func MessageArgs

func MessageArgs(args ...any) ErrorOption

type MiniError

type MiniError struct {
	Code    int            `json:"code"`
	Message string         `json:"message"`
	Details map[string]any `json:"details"`
}

func NewMini

func NewMini(code int, message string, details map[string]any) *MiniError

type PropertySetter

type PropertySetter interface {
	SetMessage(string, ...any)
	FormatMessage(...any)
	SetCode(int)
	SetDetail(name, data string)
	SetError(*MiniError)
	SetHTTPStatus(int)
}

Jump to

Keyboard shortcuts

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