errors

package
v0.0.0-...-2bdc998 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2018 License: MIT Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLanguage = "en"
View Source
var ErrorMessages = map[string]map[ErrorCode]string{
	"en": {
		ErrorUserExists:          "The User already exists.",
		ErrorUsernameExists:      "This username is already registered.",
		ErrorEmailExists:         "This email is already registered.",
		ErrorUserDoesntExists:    "This user doesn't exists.",
		ErrorUserInvalidPassword: "The user and/or password didn't match.",
		ErrorUserInvalidUsername: "This username is invalid.",
		ErrorUserInvalidEmail:    "This email is invalid.",
		ErrorUserInvalid:         "This user is invalid.",
		ErrorNotEnoughInfo:       "There is not enough information to find a user.",
		ErrorNoPasswordToCompare: "There is no password to compare to.",
		ErrorMissingParam:        "A URL Param is required.",
		ErrorUnauthorized:        "You're not authorized to access this page.",
	},
	"pt-br": {
		ErrorUserExists:          "O Usuario ja existe.",
		ErrorUsernameExists:      "Esse usuario ja existe.",
		ErrorEmailExists:         "Esse email ja existe.",
		ErrorUserDoesntExists:    "Esse usuario não existe.",
		ErrorUserInvalidPassword: "O usuario e/ou senha não conferem.",
		ErrorUserInvalidUsername: "Esse nome de usuario não é valido.",
		ErrorUserInvalidEmail:    "Esse email não é valido.",
		ErrorUserInvalid:         "Usuario invalido.",
		ErrorNotEnoughInfo:       "Não tenho informação suficiente para encontrar um usuario.",
		ErrorNoPasswordToCompare: "Não tenho uma senha para compara-la.",
		ErrorMissingParam:        "Um parametro de url é obrigatorio.",
		ErrorUnauthorized:        "Você não está autorizado a acessar essa página.",
	},
}

ErrorMessages holds all error messages with support for different languages

Functions

This section is empty.

Types

type Error

type Error struct {
	Err      error
	Language string
	Message  string
	Code     ErrorCode
}

func FromCode

func FromCode(code ErrorCode) *Error

FromCode creates a new Error using a ID that should lead to a pre-defined error

func FromCodeLang

func FromCodeLang(code ErrorCode, lang string) *Error

FromCodeTranslate creates a new Error using a ID that should lead to a pre-defined error

func FromErr

func FromErr(err error) *Error

func Mask

func Mask(err error, code ErrorCode) *Error

func New

func New(msg string) *Error

New returns a error compactible with the default Go "error"

func (*Error) Error

func (e *Error) Error() string

Error gives support to native golang error it's used for testing

func (*Error) JSON

func (e *Error) JSON() map[string]interface{}

JSON converts the error to json it can used on REST APIs like `echo` and `gin`

func (*Error) String

func (e *Error) String() string

String returns the error message

type ErrorCode

type ErrorCode int
const (
	ErrorUnknown ErrorCode = iota
	ErrorUserExists
	ErrorUsernameExists
	ErrorEmailExists
	ErrorUserDoesntExists
	ErrorUserInvalidPassword
	ErrorUserInvalidUsername
	ErrorUserInvalidEmail
	ErrorUserInvalid
	ErrorNotEnoughInfo
	ErrorNoPasswordToCompare
	ErrorMissingParam
	ErrorUnauthorized

	// this is used to check for missing error messages
	TotalErrorMessages
)

ONLY INSERT NEW ERRORS AT THE END

Jump to

Keyboard shortcuts

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