common

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ErrNoResourceCode = "resource_not_found"
	ErrBadRequestCode = "invalid_request"
	ErrInternalCode   = "internal_error"
)

Variables

View Source
var (
	ErrTemporaryFailure = NewError("temporary_failure", "Please retry again later")

	// ErrNoResource represents error corresponds to http.StatusNotFound.
	ErrNoResource = NewError(ErrNoResourceCode, "can't retrieve resource")

	// ErrBadRequest represents error corresponds to http.StatusBadRequest.
	ErrBadRequest = NewError(ErrBadRequestCode, "request is invalid")

	// ErrInternal represents error corresponds to http.StatusInternalServerError.
	ErrInternal = NewError(ErrInternalCode, "internal server error")

	ErrDecoding = errors.New("decoding error")

	ErrNotModified = errors.New("not modified")
)

Functions

func InvalidRequest

func InvalidRequest(msg string) error

InvalidRequest - create error messages that are needed when validating request input

func NewErrBadRequest

func NewErrBadRequest(msgs ...string) error

NewErrBadRequest creates new Error with ErrBadRequestCode.

func NewErrInternal

func NewErrInternal(msgs ...string) error

NewErrInternal creates new Error with ErrInternalCode.

func NewErrNoResource

func NewErrNoResource(msgs ...string) error

NewErrNoResource creates new Error with ErrNoResourceCode.

Types

type Error

type Error struct {
	Code string `json:"code,omitempty"`
	Msg  string `json:"msg"`
}

Error type for a new application error

func NewError

func NewError(code string, msg string) *Error

NewError - create a new error

func NewErrorf

func NewErrorf(code string, format string, args ...interface{}) *Error

NewErrorf - create a new formated error

func (*Error) Error

func (err *Error) Error() string

func (*Error) Is

func (err *Error) Is(target error) bool

Jump to

Keyboard shortcuts

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