errors

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMethodNotAllow = ErrorMethodNotAllow.New()
	ErrNoPermission   = ErrorNoPermission.New()
	ErrNotFound       = ErrorNotFound.New()
	ErrTokenExpired   = ErrorTokenExpired.New()
	ErrTokenInvalid   = ErrorTokenInvalid.New()
	ErrTokenMalformed = ErrorTokenMalformed.New()
)

Define some template errors

View Source
var ErrorCodeMap = map[ErrorType]string{
	Success:                    "SUCCESS",
	Error:                      "ERROR",
	InvalidParams:              "INVALID_PARAMS",
	ErrorAuthCheckTokenFail:    "ERROR_AUTH_CHECK_TOKEN_FAIL",
	ErrorAuthCheckTokenTimeout: "ERROR_AUTH_CHECK_TOKEN_TIMEOUT",
	ErrorAuthToken:             "ERROR_AUTH_TOKEN",
	ErrorAuth:                  "ERROR_AUTH",
	ErrorInternalServer:        "ERROR_INTERNAL_SERVER",
	ErrorExistEmail:            "ERROR_EXIST_EMAIL",
	ErrorBadRequest:            "ERROR_BAD_REQUEST",
	ErrorInvalidParent:         "ERROR_INVALID_PARENT",
	ErrorAllowDeleteWithChild:  "ERROR_ALLOW_DELETE_WITH_CHILD",
	ErrorNotAllowDelete:        "ERROR_NOT_ALLOW_DELETE",
	ErrorInvalidOldPass:        "ERROR_INVALID_OLD_PASS",
	ErrorNotFound:              "ERROR_NOT_FOUND",
	ErrorPasswordRequired:      "ERROR_PASSWORD_REQUIRED",
	ErrorExistMenuName:         "ERROR_EXIST_MENU_NAME",
	ErrorUserDisabled:          "ERROR_USER_DISABLED",
	ErrorNoPermission:          "ERROR_NO_PERMISSION",
	ErrorMethodNotAllow:        "ERROR_METHOD_NOT_ALLOW",
	ErrorTooManyRequest:        "ERROR_TOO_MANY_REQUEST",
	ErrorLoginFailed:           "ERROR_LOGIN_FAILED",
	ErrorExistRole:             "ERROR_EXIST_ROLE",
	ErrorNotExistUser:          "ERROR_NOT_EXIST_USER",
	ErrorExistRoleUser:         "ERROR_EXIST_ROLE_USER",
	ErrorNotExistRole:          "ERROR_NOT_EXIST_ROLE",
	ErrorTokenExpired:          "ERROR_TOKEN_EXPIRED",
	ErrorTokenInvalid:          "ERROR_TOKEN_INVALID",
	ErrorTokenMalformed:        "ERROR_TOKEN_MALFORMED",
}

ErrorCodeMap define map error and error message

View Source
var MsgMap = map[ErrorType]string{
	Success:                    "OK",
	InvalidParams:              "Request parameter error - %s",
	ErrorAuthCheckTokenFail:    "Token authentication failed",
	ErrorAuthCheckTokenTimeout: "Token time out",
	ErrorAuthToken:             "Token build failed",
	ErrorAuth:                  "Token error",
	Error:                      "Error occurred",
	ErrorInternalServer:        "Server error",
	ErrorExistEmail:            "The Email Address entered already exists in the system",
	ErrorBadRequest:            "Request error",
	ErrorInvalidParent:         "Invalid parent node",
	ErrorAllowDeleteWithChild:  "Contains children, cannot be deleted",
	ErrorNotAllowDelete:        "Resources are not allowed to be deleted",
	ErrorInvalidOldPass:        "Old password is incorrect",
	ErrorNotFound:              "Resource does not exist",
	ErrorPasswordRequired:      "Password is required",
	ErrorExistMenuName:         "Menu name already exists",
	ErrorUserDisabled:          "User is disabled, please contact administrator",
	ErrorNoPermission:          "No access",
	ErrorMethodNotAllow:        "Method is not allowed",
	ErrorTooManyRequest:        "Requests are too frequent",
	ErrorLoginFailed:           "Email or password is invalid",
	ErrorExistRole:             "Role name already exists",
	ErrorNotExistUser:          "Account is invalid",
	ErrorExistRoleUser:         "The role has been given to the user and is not allowed to be deleted",
	ErrorNotExistRole:          "Role user is disabled, please contact administrator",
	ErrorTokenExpired:          "Token is expired",
	ErrorTokenInvalid:          "Token is invalid",
	ErrorTokenMalformed:        "That's not even a token",
}

MsgMap message map

Functions

func AddErrorContext

func AddErrorContext(err error, field, message string) error

AddErrorContext adds a context to an error

func Cause

func Cause(err error) error

Cause gives the original error

func GetCode

func GetCode(status int) string

GetCode get error code

func GetErrorContext

func GetErrorContext(err error) map[string]string

GetErrorContext returns the error context

func GetMsg

func GetMsg(status int) string

GetMsg from status

func New

func New(msg string) error

New creates a no type error

func Newf

func Newf(msg string, args ...interface{}) error

Newf creates a no type error with formatted message

func Stack

func Stack(err error) string

Stack get stacktrace of error

func Wrap

func Wrap(err error, msg string) error

Wrap wrans an error with a string

func Wrapf

func Wrapf(err error, msg string, args ...interface{}) error

Wrapf wraps an error with format string

Types

type CustomError

type CustomError struct {
	// contains filtered or unexported fields
}

CustomError struct

func (CustomError) Error

func (err CustomError) Error() string

Error return error message

func (CustomError) Stacktrace

func (err CustomError) Stacktrace() string

Stacktrace return error stacktrace message

type ErrorType

type ErrorType int

ErrorType type

const (
	Success                    ErrorType = 200
	Error                      ErrorType = 500
	InvalidParams              ErrorType = 400
	ErrorBadRequest            ErrorType = 421
	ErrorNoPermission          ErrorType = 403
	ErrorNotFound              ErrorType = 404
	ErrorMethodNotAllow        ErrorType = 405
	ErrorInvalidParent         ErrorType = 409
	ErrorAllowDeleteWithChild  ErrorType = 410
	ErrorNotAllowDelete        ErrorType = 411
	ErrorUserDisabled          ErrorType = 412
	ErrorExistMenuName         ErrorType = 413
	ErrorExistRole             ErrorType = 414
	ErrorExistRoleUser         ErrorType = 415
	ErrorNotExistUser          ErrorType = 416
	ErrorLoginFailed           ErrorType = 422
	ErrorInvalidOldPass        ErrorType = 423
	ErrorPasswordRequired      ErrorType = 424
	ErrorTooManyRequest        ErrorType = 429
	ErrorInternalServer        ErrorType = 512
	ErrorAuthCheckTokenFail    ErrorType = 401
	ErrorAuthCheckTokenTimeout ErrorType = 402
	ErrorAuthToken             ErrorType = 408
	ErrorAuth                  ErrorType = 407
	ErrorExistEmail            ErrorType = 430
	ErrorNotExistRole          ErrorType = 431
	ErrorTokenExpired          ErrorType = 461
	ErrorTokenInvalid          ErrorType = 462
	ErrorTokenMalformed        ErrorType = 463

	// System errors
	ErrorMarshal ErrorType = iota + 1000
	ErrorUnmarshal
	ErrorDatabaseGet
	ErrorDatabaseCreate
	ErrorDatabaseUpdate
	ErrorDatabaseDelete

	ErrorInvalidPassword
)

constants define error types

func GetType

func GetType(err error) ErrorType

GetType returns the error type

func (ErrorType) New

func (errType ErrorType) New() error

New error

func (ErrorType) Newf

func (errType ErrorType) Newf(msg string, args ...interface{}) error

Newf creates a new CustomError with formatted message

func (ErrorType) Newm

func (errType ErrorType) Newm(msg string) error

Newm new error with message

func (ErrorType) Wrap

func (errType ErrorType) Wrap(err error, msg string) error

Wrap creates a new wrapped error

func (ErrorType) Wrapf

func (errType ErrorType) Wrapf(err error, msg string, args ...interface{}) error

Wrapf creates a new wrapped error with formatted message

Jump to

Keyboard shortcuts

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