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: 0 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Messages = map[ID]string{
	ErrorUserNotFound: "Error: the user specified was not found",
}

Messages is a list with default error messages key: ErrorID - val: Message

Functions

This section is empty.

Types

type Error

type Error struct {
	ID      ID
	Message string
}

Error is similar to the default error struct from golang but this one specified a ID

func FromError

func FromError(err error) *Error

FromError builds a "Error" from native golang error

func New

func New(msg string) *Error

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

func NewFromID

func NewFromID(id ID) *Error

New creates a new 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's used on APIs

func (*Error) String

func (e *Error) String() string

String returns the error message

type ID

type ID int

ID is a custom type for errors ids

const (
	ErrorUserInvalidUsername ID = 1 // invalid username - when a username is not in [a-zA-Z0-9_]
	ErrorUserInvalidEmail    ID = 2 // invalid email
	ErrorUserInvalidPassword ID = 3 // invalid password - when a password is bigger than 255

	ErrorUserUsernameExists ID = 4
	ErrorUserEmailExists    ID = 5

	ErrorUserNotFound     ID = 6 // user doesn't exists
	ErrorUserNotSpecified ID = 7 // not specified - when a field doesn't have a value when looking for a user

	ErrorUserBanned             ID = 8  // banned
	ErrorUserNoPower            ID = 9  // no power - when a user doesn't have enough power
	ErrorUserTokenInvalidMethod ID = 10 // invalid token method - when a JWT header is invalid

	ErrorUserUnauthorized ID = 97 // Unauthorized
	ErrorUserInvalidInfo  ID = 98 // Invalid info - when a user information is invalid when provided from a url like (GET: api/user/ufo@usa.gov/exists)
	ErrorUserUnknown      ID = 99 // I Don't know what the error is, and at this point, i'm too afraid to ask
)

we'll not use "<< iota" because it may break things if i add a new error

Jump to

Keyboard shortcuts

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