errno

package
v0.0.0-...-ec76f1a Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// OK represents a successful request.
	OK = &Errno{Code: 0, Message: "OK"}

	// InternalServerError represents all unknown server-side errors.
	InternalServerError = &Errno{Code: 10001, Message: "Internal server error"}

	// ErrBind represents a failed parameter binding.
	ErrBind = &Errno{Code: 10002, Message: "Error occurred while binding the request body to the struct."}

	// ErrPageNotFound represents a route not matched error.
	ErrPageNotFound = &Errno{Code: 10003, Message: "Page not found."}

	// ErrValidation represents all validation failed errors.
	ErrValidation = &Errno{Code: 20001, Message: "Validation failed."}

	// ErrDatabase represents a database error.
	ErrDatabase = &Errno{Code: 20002, Message: "Database error."}

	// ErrToken represents a error when signing JWT token.
	ErrToken = &Errno{Code: 20003, Message: "Error occurred while signing the JSON web token."}

	// ErrEncrypt represents a encrypting error.
	ErrEncrypt = &Errno{Code: 20101, Message: "Error occurred while encrypting the user password."}

	// ErrUserNotFound represents the user not found.
	ErrUserNotFound = &Errno{Code: 20102, Message: "User was not found."}

	// ErrUserAlreadyExist represents the user already exist.
	ErrUserAlreadyExist = &Errno{Code: 20103, Message: "User already exist."}

	// ErrTokenInvalid represents the token format is wrong.
	ErrTokenInvalid = &Errno{Code: 20104, Message: "Token was invalid."}

	// ErrPasswordIncorrect represents the password is incorrect.
	ErrPasswordIncorrect = &Errno{Code: 20105, Message: "Password was incorrect."}

	// ErrPostNotFound represents  the post not found.
	ErrPostNotFound = &Errno{Code: 20201, Message: "Post was not found."}

	// ErrPostAlreadyExist represents the post already exist.
	ErrPostAlreadyExist = &Errno{Code: 20202, Message: "Post already exist."}
)

Functions

func DecodeErr

func DecodeErr(err error) (int, string)

DecodeErr decode an err message.

func IsErrUserNotFound

func IsErrUserNotFound(err error) bool

IsErrUserNotFound return true if the `err` is a `ErrUserNotFound` type error.

Types

type Err

type Err struct {
	Code    int
	Message string
	Err     error
}

Err represents an error.

func New

func New(errno *Errno, err error) *Err

New create a new `Err` error.

func (*Err) Add

func (err *Err) Add(message string) error

Add add message to `Err` error.

func (*Err) Addf

func (err *Err) Addf(format string, args ...interface{}) error

Addf add a formated message to `Err` error.

func (*Err) Error

func (err *Err) Error() string

Error return error message in string format.

type Errno

type Errno struct {
	Code    int
	Message string
}

Errno defines a new error type used by goserver.

func (Errno) Error

func (err Errno) Error() string

Error implement the `Error` method in error interface.

Jump to

Keyboard shortcuts

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