kerror

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2025 License: MIT Imports: 17 Imported by: 0

README

kerror

Kerror is a custom error handler

Documentation

Index

Constants

View Source
const (
	EmailRegexPattern    = `^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,4}$`
	PhoneRegexPattern    = `^\+?[1-9]\d{10,15}$`
	PinRegexPattern      = `^\d{4,12}$`
	PasswordRegexPattern = `^(?=.*[A-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[*@$!%*#?&])\S{8,}$`
)

Variables

Functions

func GetJSONTag

func GetJSONTag(fld reflect.StructField) string

GetJSONTag will return the value of the json tag of the field. This func can be passed as argument to validate.RegisterTagNameFunc

func HTTPErrorResponse

func HTTPErrorResponse(c echo.Context, e error) error

func Is

func Is(e KisaError, k Kind) bool

Types

type FieldValidationError

type FieldValidationError struct {
	FieldName string `json:"field"`
	Error     error  `json:"message"`
}

func (FieldValidationError) MarshalJSON

func (f FieldValidationError) MarshalJSON() ([]byte, error)

type Kerror

type Kerror struct {
	Status  int
	Kind    string
	Message string
	Fields  map[string]string
	// contains filtered or unexported fields
}

func Tokerror

func Tokerror(e error) *Kerror

ToKerror takes a generic KisaError and return a structured Kerrok instance

func (Kerror) Code

func (k Kerror) Code() int

func (Kerror) Error

func (k Kerror) Error() string

func (Kerror) GetKind

func (k Kerror) GetKind() string

func (Kerror) GetMessage

func (k Kerror) GetMessage() string

func (Kerror) GetValidationFields

func (k Kerror) GetValidationFields() map[string]string

func (Kerror) Unwrap

func (k Kerror) Unwrap() error

func (*Kerror) With

func (k *Kerror) With(contextArgs ...interface{}) KisaError

type Kind

type Kind uint8
const (
	ErrUnkown Kind = iota
	ErrInvalidRequest
	ErrNotFound
	ErrResourceConflict
	ErrInternalServer
	ErrValidation
	ErrDatabase
	ErrUnauthorized
	ErrForbidden
	ErrRequestTimeout
	ErrEchoServer
	ErrNoToken
	ErrInvalidToken
	ErrInvalidJWTClaims
)

func (Kind) String

func (k Kind) String() string

type KisaError

type KisaError interface {
	Error() string
	GetMessage() string
	Code() int
	With(...interface{}) KisaError
	GetValidationFields() map[string]string
	GetKind() string
	// contains filtered or unexported methods
}

func BindError

func BindError(err error, message string) KisaError

func DatabaseError

func DatabaseError(err error, log logam.Logger) KisaError

func ForbidenError

func ForbidenError(message string, err error) KisaError

func InternalServerError

func InternalServerError(err error) KisaError

func InvalidApiKeyError

func InvalidApiKeyError(err error) KisaError

func InvalidAuthMethodError

func InvalidAuthMethodError(err error) KisaError

func InvalidJWTClaimsError

func InvalidJWTClaimsError(err error) KisaError

func InvalidKeyAttributesError

func InvalidKeyAttributesError(err error) KisaError

func InvalidRequestError

func InvalidRequestError(message string, err error) KisaError

func InvalidTokenError

func InvalidTokenError(err error) KisaError

func NoTokenError

func NoTokenError(err error) KisaError

func NotFoundError

func NotFoundError(message string, err error) KisaError

func ResourceConflictError

func ResourceConflictError(message string, err error) KisaError

func UnauthorizedError

func UnauthorizedError(message string, err error) KisaError

func ValidationError

func ValidationError(err validationFields) KisaError

type LogContext

type LogContext map[string]interface{}

type Validator

type Validator struct {
	*validator.Validate
	// contains filtered or unexported fields
}

func New

func New() *Validator

func (*Validator) VStruct

func (v *Validator) VStruct(s interface{}) []FieldValidationError

Jump to

Keyboard shortcuts

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