merror

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: MIT Imports: 2 Imported by: 0

README

merror is a set of functions for handling standardized errors in applications using the HTTP/S protocol.

Package extracted from https://github.com/malumar/tempf

Documentation

Index

Constants

View Source
const (
	NotFoundMessage            = "not found"
	ForbiddenMessage           = "forbidden"
	UnauthorizedMessage        = "unauthorized"
	InternalServerErrorMessage = "internal server error"
	UnprocessableMessage       = "unprocessable entity"
)

Variables

View Source
var DefaultMessageIfEmpty = ""
View Source
var ErrForbiddenCode = 403
View Source
var ErrInternalServerCode = 501
View Source
var ErrNotFoundCode = 404

you can register custom error codes below basic codes

View Source
var ErrUnauthorizedCode = 401
View Source
var ErrUnprocessableEntity = 422
View Source
var UndefinedErrorCode = -1

Functions

func Cause

func Cause(err error) error

Cause returns to the parent and returns the root cause of the error implements the "causer" interface.

func Code

func Code(err error) int

func GetCode

func GetCode(code int, dfault string) string

func Is

func Is(err error) bool

func SetCode

func SetCode(code int, value string)

func UnWrap

func UnWrap(err error) error

The UnWrap function takes an error and return unwraped error.

Types

type CauseHolder

type CauseHolder interface {
	Cause() error
}

type Error

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

func New

func New(code int, casue error, comment string) *Error

func NewForbidden

func NewForbidden() *Error

func NewForbiddenWrap

func NewForbiddenWrap(err error) *Error

func NewInternalServer

func NewInternalServer() *Error

func NewInternalServerWrap

func NewInternalServerWrap(err error) *Error

func NewNotFound

func NewNotFound() *Error

func NewNotFoundWrap

func NewNotFoundWrap(err error) *Error

func NewUnauthorized

func NewUnauthorized() *Error

func NewUnauthorizedWrap

func NewUnauthorizedWrap(err error) *Error

func NewUnprocessableEntity

func NewUnprocessableEntity() *Error

func NewUnprocessableEntityWrap

func NewUnprocessableEntityWrap(err error) *Error

func (*Error) Cause

func (self *Error) Cause() error

func (*Error) Code

func (self *Error) Code() int

func (*Error) Error

func (self *Error) Error() string

func (*Error) SetCode

func (self *Error) SetCode(code int) *Error

func (*Error) SetComment

func (self *Error) SetComment(comment string) *Error

func (*Error) SetCommentf

func (self *Error) SetCommentf(format string, args ...interface{}) *Error

func (*Error) String

func (self *Error) String() string

Jump to

Keyboard shortcuts

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