apperr

package
v2.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSyntax               = New("syntax_error", WithTextTranslate(i18n.ErrSyntax), WithCode(code.InvalidArgument))
	ErrValidation           = New("validation_error", WithTextTranslate(i18n.ErrValidation), WithCode(code.InvalidArgument))
	ErrEmptyData            = New("empty_data_error", WithTextTranslate(i18n.ErrEmptyData), WithCode(code.InvalidArgument))
	ErrInternal             = New("internal_error", WithTextTranslate(i18n.ErrInternal), WithCode(code.Internal))
	ErrForbidden            = New("forbidden_error", WithTextTranslate(i18n.ErrForbidden), WithCode(code.PermissionDenied))
	ErrUnauthenticated      = New("unauthenticated_error", WithTextTranslate(i18n.ErrUnauthenticated), WithCode(code.Unauthenticated))
	ErrNotFound             = New("not_found_error", WithTextTranslate(i18n.ErrNotFound), WithCode(code.NotFound))
	ErrServerIsNotAvailable = New("server_is_not_available", WithTextTranslate(i18n.ErrServerIsNotAvailable), WithCode(code.Unavailable))
)
View Source
var (
	ErrDBRecordNotFound = New("db_not_found", WithTextTranslate(i18n.ErrDBRecordNotFound), WithCode(code.NotFound))
	ErrDBDuplicated     = New("db_duplicated", WithTextTranslate(i18n.ErrDBDuplicated), WithCode(code.NotFound))
	ErrDBInternal       = New("db_internal", WithTextTranslate(i18n.ErrDBInternal), WithCode(code.NotFound))
)

Functions

func Is

func Is(err, target error) bool

func Translate

func Translate(err Error, lang string) string

Types

type Annotator

type Annotator func(*Error)

func WithCode

func WithCode(code code.Code) Annotator

func WithID

func WithID(id string) Annotator

func WithText

func WithText(text string) Annotator

func WithTextTranslate

func WithTextTranslate(tr translator.Translate) Annotator

type Error

type Error struct {
	ID                string
	Code              code.Code
	Text              string
	TextTranslate     translator.Translate
	TextTranslateArgs []interface{}
	Err               error
}

func New

func New(id string, annotators ...Annotator) Error

func Replace

func Replace(err Error, annotators ...Annotator) Error

func (Error) Error

func (e Error) Error() string

func (Error) GetIDPrefix added in v2.0.4

func (e Error) GetIDPrefix() string

func (Error) LastError

func (e Error) LastError() error

func (Error) NewID

func (e Error) NewID(id string) Error

func (Error) WithError

func (e Error) WithError(err error) Error

func (Error) WithErrorText

func (e Error) WithErrorText(err string) Error

func (Error) WithTextArgs

func (e Error) WithTextArgs(args ...any) Error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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