apperr

package
v1.0.36 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSyntax = New(StatusInternalServerError, "syntax_error").WithTextTranslate(Translate{
		"ru": "Неверный запрос",
	})
	ErrValidation = New(StatusBadRequest, "validation_error").WithTextTranslate(Translate{
		"ru": "Неверный запрос",
	})
	ErrEmptyData = New(StatusInternalServerError, "empty_data_error").WithTextTranslate(Translate{
		"ru": "Неверный запрос",
	})
	ErrInternal = New(StatusInternalServerError, "internal_error").WithTextTranslate(Translate{
		"ru": "Ошибка сервера",
	})
	ErrForbidden = New(StatusForbidden, "forbidden_error").WithTextTranslate(Translate{
		"ru": "Нет доступа",
	})
	ErrUnauthenticated = New(StatusUnauthenticated, "unauthorized_error").WithTextTranslate(Translate{
		"ru": "Ошибка аутентификации",
	})
	ErrNotFound = New(StatusNotFound, "not_found_error").WithTextTranslate(Translate{
		"ru": "Не найдено",
	})
	ErrServerIsNotAvailable = New(StatusInternalServerError, "server_is_not_available").WithTextTranslate(Translate{
		"ru": "Сервер недоступен",
	})
	Err404 = New(StatusInternalServerError, "invalid_request").WithTextTranslate(Translate{
		"ru": "Неверный запрос",
	})
)

Functions

func GRPCResponse

func GRPCResponse(err error) error

func HTTPResponse

func HTTPResponse(c *gin.Context, err error)

HTTPResponse writes an error response to client

func Is

func Is(err, target error) bool

func RegisterTagNameFunc

func RegisterTagNameFunc(fld reflect.StructField) string

func SetTranslators

func SetTranslators(validate *validator.Validate)

Types

type APPError

type APPError struct {
	ID                string `json:"id"`
	Title             string `json:"title"`
	Text              string `json:"text"`
	Context           string `json:"context"`
	ShowMessageBanner bool   `json:"show_message_banner"`

	MethodID           string        `json:"-"`
	TextTranslate      Translate     `json:"-"`
	TextTranslateArgs  []interface{} `json:"-"`
	TitleTranslate     Translate     `json:"-"`
	TitleTranslateArgs []interface{} `json:"-"`
	Status             Code          `json:"-"`
	Err                error         `json:"-"`
}

func New

func New(status Code, id string) *APPError

func NewMethod added in v1.0.27

func NewMethod(methodID string, context string) *APPError

func ParseGRPCError added in v1.0.29

func ParseGRPCError(err error) *APPError

func (APPError) Combine added in v1.0.27

func (e APPError) Combine(err *APPError) *APPError

func (APPError) Error

func (e APPError) Error() string

func (APPError) Translate

func (e APPError) Translate(lang string) *APPError

func (APPError) WithError

func (e APPError) WithError(err error) *APPError

func (APPError) WithShowMessageBanner

func (e APPError) WithShowMessageBanner(showMessageBanner bool) *APPError

func (APPError) WithStatus

func (e APPError) WithStatus(status Code) *APPError

func (APPError) WithTextTranslate added in v1.0.27

func (e APPError) WithTextTranslate(translate Translate) *APPError

func (APPError) WithTextTranslateArgs added in v1.0.27

func (e APPError) WithTextTranslateArgs(args ...interface{}) *APPError

func (APPError) WithTitleTranslate added in v1.0.27

func (e APPError) WithTitleTranslate(translate Translate) *APPError

func (APPError) WithTitleTranslateArgs added in v1.0.27

func (e APPError) WithTitleTranslateArgs(args ...interface{}) *APPError

type Code

type Code int
const (
	StatusBadRequest Code = iota
	StatusUnauthenticated
	StatusForbidden
	StatusNotFound
	StatusInternalServerError
)

func (Code) GRPC

func (c Code) GRPC() codes.Code

func (Code) HTTP

func (c Code) HTTP() int

type Translate

type Translate map[string]string

func (Translate) Translate

func (t Translate) Translate(acceptLang string, args ...interface{}) string

func (Translate) TranslateHttp

func (t Translate) TranslateHttp(c *gin.Context, args ...interface{}) string

type ValidateError added in v1.0.1

type ValidateError struct {
	Column string `json:"column"`
	Error  string `json:"error"`
}

Jump to

Keyboard shortcuts

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