errs

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SystemSubcategoryDefault  = 0
	SystemSubcategorySetting  = 1
	SystemSubcategoryDatabase = 2
	SystemSubcategoryMail     = 3
)

Sub categories of system error

View Source
const (
	NormalSubcategoryGlobal         = 0
	NormalSubcategoryUser           = 1
	NormalSubcategoryToken          = 2
	NormalSubcategoryTwofactor      = 3
	NormalSubcategoryAccount        = 4
	NormalSubcategoryTransaction    = 5
	NormalSubcategoryCategory       = 6
	NormalSubcategoryTag            = 7
	NormalSubcategoryDataManagement = 8
	NormalSubcategoryMapProxy       = 9
)

Sub categories of normal error

Variables

View Source
var (
	ErrAccountIdInvalid                       = NewNormalError(NormalSubcategoryAccount, 0, http.StatusBadRequest, "account id is invalid")
	ErrAccountNotFound                        = NewNormalError(NormalSubcategoryAccount, 1, http.StatusBadRequest, "account not found")
	ErrAccountTypeInvalid                     = NewNormalError(NormalSubcategoryAccount, 2, http.StatusBadRequest, "account type is invalid")
	ErrAccountCurrencyInvalid                 = NewNormalError(NormalSubcategoryAccount, 3, http.StatusBadRequest, "account currency is invalid")
	ErrAccountHaveNoSubAccount                = NewNormalError(NormalSubcategoryAccount, 4, http.StatusBadRequest, "account must have at least one sub-account")
	ErrAccountCannotHaveSubAccounts           = NewNormalError(NormalSubcategoryAccount, 5, http.StatusBadRequest, "account cannot have sub-accounts")
	ErrParentAccountCannotSetCurrency         = NewNormalError(NormalSubcategoryAccount, 6, http.StatusBadRequest, "parent account cannot set currency")
	ErrParentAccountCannotSetBalance          = NewNormalError(NormalSubcategoryAccount, 7, http.StatusBadRequest, "parent account cannot set balance")
	ErrSubAccountCategoryNotEqualsToParent    = NewNormalError(NormalSubcategoryAccount, 8, http.StatusBadRequest, "sub-account category not equals to parent")
	ErrSubAccountTypeInvalid                  = NewNormalError(NormalSubcategoryAccount, 9, http.StatusBadRequest, "sub-account type invalid")
	ErrCannotAddOrDeleteSubAccountsWhenModify = NewNormalError(NormalSubcategoryAccount, 10, http.StatusBadRequest, "cannot add or delete sub-accounts when modify account")
	ErrSourceAccountNotFound                  = NewNormalError(NormalSubcategoryAccount, 11, http.StatusBadRequest, "source account not found")
	ErrDestinationAccountNotFound             = NewNormalError(NormalSubcategoryAccount, 12, http.StatusBadRequest, "destination account not found")
	ErrAccountInUseCannotBeDeleted            = NewNormalError(NormalSubcategoryAccount, 13, http.StatusBadRequest, "account is in use and cannot be deleted")
)

Error codes related to accounts

View Source
var (
	ErrDatabaseTypeInvalid     = NewSystemError(SystemSubcategoryDatabase, 0, http.StatusInternalServerError, "database type is invalid")
	ErrDatabaseHostInvalid     = NewSystemError(SystemSubcategoryDatabase, 1, http.StatusInternalServerError, "database host is invalid")
	ErrDatabaseIsNull          = NewSystemError(SystemSubcategoryDatabase, 2, http.StatusInternalServerError, "database cannot be null")
	ErrDatabaseOperationFailed = NewSystemError(SystemSubcategoryDatabase, 3, http.StatusInternalServerError, "database operation failed")
)

Error codes related to database

View Source
var (
	ErrIncompleteOrIncorrectSubmission = NewNormalError(NormalSubcategoryGlobal, 0, http.StatusBadRequest, "incomplete or incorrect submission")
	ErrOperationFailed                 = NewNormalError(NormalSubcategoryGlobal, 1, http.StatusInternalServerError, "operation failed")
	ErrRequestIdInvalid                = NewNormalError(NormalSubcategoryGlobal, 2, http.StatusInternalServerError, "request id is invalid")
	ErrCiphertextInvalid               = NewNormalError(NormalSubcategoryGlobal, 3, http.StatusInternalServerError, "ciphertext is invalid")
	ErrNothingWillBeUpdated            = NewNormalError(NormalSubcategoryGlobal, 4, http.StatusBadRequest, "nothing will be updated")
	ErrFailedToRequestRemoteApi        = NewNormalError(NormalSubcategoryGlobal, 5, http.StatusBadRequest, "failed to request third party api")
	ErrPageIndexInvalid                = NewNormalError(NormalSubcategoryGlobal, 6, http.StatusBadRequest, "page index is invalid")
	ErrPageCountInvalid                = NewNormalError(NormalSubcategoryGlobal, 7, http.StatusBadRequest, "page count is invalid")
	ErrClientTimezoneOffsetInvalid     = NewNormalError(NormalSubcategoryGlobal, 8, http.StatusBadRequest, "client timezone offset is invalid")
	ErrQueryItemsEmpty                 = NewNormalError(NormalSubcategoryGlobal, 9, http.StatusBadRequest, "query items cannot be blank")
	ErrQueryItemsTooMuch               = NewNormalError(NormalSubcategoryGlobal, 10, http.StatusBadRequest, "query items too much")
	ErrQueryItemsInvalid               = NewNormalError(NormalSubcategoryGlobal, 11, http.StatusBadRequest, "query items have invalid item")
	ErrParameterInvalid                = NewNormalError(NormalSubcategoryGlobal, 12, http.StatusBadRequest, "parameter invalid")
	ErrFormatInvalid                   = NewNormalError(NormalSubcategoryGlobal, 13, http.StatusBadRequest, "format invalid")
)

General error codes

View Source
var (
	ErrSMTPServerNotEnabled  = NewSystemError(SystemSubcategoryMail, 0, http.StatusInternalServerError, "SMTP server is not enabled")
	ErrSMTPServerHostInvalid = NewSystemError(SystemSubcategoryMail, 1, http.StatusInternalServerError, "SMTP server host is invalid")
)

Error codes related to mail

View Source
var (
	ErrMapProviderNotCurrent      = NewNormalError(NormalSubcategoryMapProxy, 0, http.StatusBadRequest, "specified map provider is not set")
	ErrImageExtensionNotSupported = NewNormalError(NormalSubcategoryMapProxy, 0, http.StatusNotFound, "specified image extension is not supported")
)

Error codes related to map image proxy

View Source
var (
	ErrInvalidProtocol                       = NewSystemError(SystemSubcategorySetting, 0, http.StatusInternalServerError, "invalid server protocol")
	ErrInvalidLogMode                        = NewSystemError(SystemSubcategorySetting, 1, http.StatusInternalServerError, "invalid log mode")
	ErrGettingLocalAddress                   = NewSystemError(SystemSubcategorySetting, 2, http.StatusInternalServerError, "failed to get local address")
	ErrInvalidUuidMode                       = NewSystemError(SystemSubcategorySetting, 3, http.StatusInternalServerError, "invalid uuid mode")
	ErrInvalidExchangeRatesDataSource        = NewSystemError(SystemSubcategorySetting, 4, http.StatusInternalServerError, "invalid exchange rates data source")
	ErrInvalidMapProvider                    = NewSystemError(SystemSubcategorySetting, 5, http.StatusInternalServerError, "invalid map provider")
	ErrInvalidAmapSecurityVerificationMethod = NewSystemError(SystemSubcategorySetting, 6, http.StatusInternalServerError, "invalid amap security verification method")
)

Error codes related to settings

View Source
var (
	ErrSystemError      = NewSystemError(SystemSubcategoryDefault, 0, http.StatusInternalServerError, "system error")
	ErrApiNotFound      = NewSystemError(SystemSubcategoryDefault, 1, http.StatusNotFound, "api not found")
	ErrMethodNotAllowed = NewSystemError(SystemSubcategoryDefault, 2, http.StatusMethodNotAllowed, "method not allowed")
	ErrNotImplemented   = NewSystemError(SystemSubcategoryDefault, 3, http.StatusNotImplemented, "not implemented")
	ErrSystemIsBusy     = NewSystemError(SystemSubcategoryDefault, 4, http.StatusNotImplemented, "system is busy")
	ErrNotSupported     = NewSystemError(SystemSubcategoryDefault, 5, http.StatusBadRequest, "not supported")
)

Error codes related to transaction categories

View Source
var (
	ErrTokenGenerating                      = NewNormalError(NormalSubcategoryToken, 0, http.StatusInternalServerError, "failed to generate token")
	ErrUnauthorizedAccess                   = NewNormalError(NormalSubcategoryToken, 1, http.StatusUnauthorized, "unauthorized access")
	ErrCurrentInvalidToken                  = NewNormalError(NormalSubcategoryToken, 2, http.StatusUnauthorized, "current token is invalid")
	ErrCurrentTokenExpired                  = NewNormalError(NormalSubcategoryToken, 3, http.StatusUnauthorized, "current token is expired")
	ErrCurrentInvalidTokenType              = NewNormalError(NormalSubcategoryToken, 4, http.StatusUnauthorized, "current token type is invalid")
	ErrCurrentTokenRequire2FA               = NewNormalError(NormalSubcategoryToken, 5, http.StatusUnauthorized, "current token requires two-factor authorization")
	ErrCurrentTokenNotRequire2FA            = NewNormalError(NormalSubcategoryToken, 6, http.StatusUnauthorized, "current token does not require two-factor authorization")
	ErrInvalidToken                         = NewNormalError(NormalSubcategoryToken, 7, http.StatusBadRequest, "token is invalid")
	ErrInvalidTokenId                       = NewNormalError(NormalSubcategoryToken, 8, http.StatusBadRequest, "token id is invalid")
	ErrInvalidUserTokenId                   = NewNormalError(NormalSubcategoryToken, 9, http.StatusBadRequest, "user token id is invalid")
	ErrTokenRecordNotFound                  = NewNormalError(NormalSubcategoryToken, 10, http.StatusBadRequest, "token is not found")
	ErrTokenExpired                         = NewNormalError(NormalSubcategoryToken, 11, http.StatusBadRequest, "token is expired")
	ErrTokenIsEmpty                         = NewNormalError(NormalSubcategoryToken, 12, http.StatusBadRequest, "token is empty")
	ErrEmailVerifyTokenIsInvalidOrExpired   = NewNormalError(NormalSubcategoryToken, 13, http.StatusBadRequest, "email verify token is invalid or expired")
	ErrPasswordResetTokenIsInvalidOrExpired = NewNormalError(NormalSubcategoryToken, 14, http.StatusBadRequest, "password reset token is invalid or expired")
)

Error codes related to tokens

View Source
var (
	ErrTransactionIdInvalid                                = NewNormalError(NormalSubcategoryTransaction, 0, http.StatusBadRequest, "transaction id is invalid")
	ErrTransactionNotFound                                 = NewNormalError(NormalSubcategoryTransaction, 1, http.StatusBadRequest, "transaction not found")
	ErrTransactionTypeInvalid                              = NewNormalError(NormalSubcategoryTransaction, 2, http.StatusBadRequest, "transaction type is invalid")
	ErrTransactionSourceAndDestinationIdCannotBeEqual      = NewNormalError(NormalSubcategoryTransaction, 3, http.StatusBadRequest, "transaction source and destination account id cannot be equal")
	ErrTransactionSourceAndDestinationAmountNotEqual       = NewNormalError(NormalSubcategoryTransaction, 4, http.StatusBadRequest, "transaction source and destination amount not equal")
	ErrTransactionDestinationAccountCannotBeSet            = NewNormalError(NormalSubcategoryTransaction, 5, http.StatusBadRequest, "transaction destination account cannot be set")
	ErrTransactionDestinationAmountCannotBeSet             = NewNormalError(NormalSubcategoryTransaction, 6, http.StatusBadRequest, "transaction destination amount cannot be set")
	ErrTooMuchTransactionInOneSecond                       = NewNormalError(NormalSubcategoryTransaction, 7, http.StatusBadRequest, "too much transaction in one second")
	ErrBalanceModificationTransactionCannotSetCategory     = NewNormalError(NormalSubcategoryTransaction, 8, http.StatusBadRequest, "balance modification transaction cannot set category")
	ErrBalanceModificationTransactionCannotChangeAccountId = NewNormalError(NormalSubcategoryTransaction, 9, http.StatusBadRequest, "balance modification transaction cannot change account id")
	ErrBalanceModificationTransactionCannotAddWhenNotEmpty = NewNormalError(NormalSubcategoryTransaction, 10, http.StatusBadRequest, "balance modification transaction cannot add when other transaction exists")
	ErrCannotAddTransactionToHiddenAccount                 = NewNormalError(NormalSubcategoryTransaction, 11, http.StatusBadRequest, "cannot add transaction to hidden account")
	ErrCannotModifyTransactionInHiddenAccount              = NewNormalError(NormalSubcategoryTransaction, 12, http.StatusBadRequest, "cannot modify transaction of hidden account")
	ErrCannotDeleteTransactionInHiddenAccount              = NewNormalError(NormalSubcategoryTransaction, 13, http.StatusBadRequest, "cannot delete transaction in hidden account")
	ErrCannotCreateTransactionWithThisTransactionTime      = NewNormalError(NormalSubcategoryTransaction, 14, http.StatusBadRequest, "cannot add transaction with this transaction time")
	ErrCannotModifyTransactionWithThisTransactionTime      = NewNormalError(NormalSubcategoryTransaction, 15, http.StatusBadRequest, "cannot modify transaction with this transaction time")
	ErrCannotDeleteTransactionWithThisTransactionTime      = NewNormalError(NormalSubcategoryTransaction, 16, http.StatusBadRequest, "cannot delete transaction with this transaction time")
)

Error codes related to transaction

View Source
var (
	ErrTransactionCategoryIdInvalid            = NewNormalError(NormalSubcategoryCategory, 0, http.StatusBadRequest, "transaction category id is invalid")
	ErrTransactionCategoryNotFound             = NewNormalError(NormalSubcategoryCategory, 1, http.StatusBadRequest, "transaction category not found")
	ErrTransactionCategoryTypeInvalid          = NewNormalError(NormalSubcategoryCategory, 2, http.StatusBadRequest, "transaction category type is invalid")
	ErrParentTransactionCategoryNotFound       = NewNormalError(NormalSubcategoryCategory, 3, http.StatusBadRequest, "parent transaction category not found")
	ErrCannotAddToSecondaryTransactionCategory = NewNormalError(NormalSubcategoryCategory, 4, http.StatusBadRequest, "cannot add to secondary transaction category")
	ErrCannotUsePrimaryCategoryForTransaction  = NewNormalError(NormalSubcategoryCategory, 5, http.StatusBadRequest, "cannot use primary category for transaction category")
	ErrTransactionCategoryInUseCannotBeDeleted = NewNormalError(NormalSubcategoryCategory, 6, http.StatusBadRequest, "transaction category is in use and cannot be deleted")
)

Error codes related to transaction categories

View Source
var (
	ErrTransactionTagIdInvalid            = NewNormalError(NormalSubcategoryTag, 0, http.StatusBadRequest, "transaction tag id is invalid")
	ErrTransactionTagNotFound             = NewNormalError(NormalSubcategoryTag, 1, http.StatusBadRequest, "transaction tag not found")
	ErrTransactionTagNameIsEmpty          = NewNormalError(NormalSubcategoryTag, 2, http.StatusBadRequest, "transaction tag name is empty")
	ErrTransactionTagNameAlreadyExists    = NewNormalError(NormalSubcategoryTag, 3, http.StatusBadRequest, "transaction tag name already exists")
	ErrTransactionTagInUseCannotBeDeleted = NewNormalError(NormalSubcategoryTag, 4, http.StatusBadRequest, "transaction tag is in use and cannot be deleted")
)

Error codes related to transaction tags

View Source
var (
	ErrPasscodeInvalid               = NewNormalError(NormalSubcategoryTwofactor, 0, http.StatusUnauthorized, "passcode is invalid")
	ErrTwoFactorRecoveryCodeInvalid  = NewNormalError(NormalSubcategoryTwofactor, 1, http.StatusUnauthorized, "two-factor backup code is invalid")
	ErrTwoFactorRecoveryCodeNotExist = NewNormalError(NormalSubcategoryTwofactor, 2, http.StatusUnauthorized, "two-factor backup code does not exist")
	ErrTwoFactorIsNotEnabled         = NewNormalError(NormalSubcategoryTwofactor, 3, http.StatusBadRequest, "two-factor is not enabled")
	ErrTwoFactorAlreadyEnabled       = NewNormalError(NormalSubcategoryTwofactor, 4, http.StatusBadRequest, "two-factor has already been enabled")
)

Error codes related to two-factor authorization

View Source
var (
	ErrLoginNameInvalid             = NewNormalError(NormalSubcategoryUser, 0, http.StatusUnauthorized, "login name is invalid")
	ErrLoginNameOrPasswordInvalid   = NewNormalError(NormalSubcategoryUser, 1, http.StatusUnauthorized, "login name or password is invalid")
	ErrLoginNameOrPasswordWrong     = NewNormalError(NormalSubcategoryUser, 2, http.StatusUnauthorized, "login name or password is wrong")
	ErrUserIdInvalid                = NewNormalError(NormalSubcategoryUser, 3, http.StatusBadRequest, "user id is invalid")
	ErrUsernameIsEmpty              = NewNormalError(NormalSubcategoryUser, 4, http.StatusBadRequest, "username is empty")
	ErrEmailIsEmpty                 = NewNormalError(NormalSubcategoryUser, 5, http.StatusBadRequest, "email is empty")
	ErrNicknameIsEmpty              = NewNormalError(NormalSubcategoryUser, 6, http.StatusBadRequest, "nickname is empty")
	ErrPasswordIsEmpty              = NewNormalError(NormalSubcategoryUser, 7, http.StatusBadRequest, "password is empty")
	ErrUserDefaultCurrencyIsEmpty   = NewNormalError(NormalSubcategoryUser, 8, http.StatusBadRequest, "user default currency is empty")
	ErrUserDefaultCurrencyIsInvalid = NewNormalError(NormalSubcategoryUser, 9, http.StatusBadRequest, "user default currency is invalid")
	ErrUserNotFound                 = NewNormalError(NormalSubcategoryUser, 10, http.StatusBadRequest, "user not found")
	ErrUserPasswordWrong            = NewNormalError(NormalSubcategoryUser, 11, http.StatusBadRequest, "password is wrong")
	ErrUsernameAlreadyExists        = NewNormalError(NormalSubcategoryUser, 12, http.StatusBadRequest, "username already exists")
	ErrUserEmailAlreadyExists       = NewNormalError(NormalSubcategoryUser, 13, http.StatusBadRequest, "email already exists")
	ErrUserRegistrationNotAllowed   = NewNormalError(NormalSubcategoryUser, 14, http.StatusBadRequest, "user registration not allowed")
	ErrUserDefaultAccountIsInvalid  = NewNormalError(NormalSubcategoryUser, 15, http.StatusBadRequest, "user default account is invalid")
	ErrUserIsDisabled               = NewNormalError(NormalSubcategoryUser, 16, http.StatusBadRequest, "user is disabled")
	ErrEmptyIsInvalid               = NewNormalError(NormalSubcategoryUser, 17, http.StatusBadRequest, "email is invalid")
	ErrEmailIsEmptyOrInvalid        = NewNormalError(NormalSubcategoryUser, 18, http.StatusBadRequest, "email is empty or invalid")
	ErrNewPasswordEqualsOldInvalid  = NewNormalError(NormalSubcategoryUser, 19, http.StatusBadRequest, "new password equals old password")
	ErrEmailIsNotVerified           = NewNormalError(NormalSubcategoryUser, 20, http.StatusBadRequest, "email is not verified")
	ErrEmailIsVerified              = NewNormalError(NormalSubcategoryUser, 21, http.StatusBadRequest, "email is verified")
	ErrEmailValidationNotAllowed    = NewNormalError(NormalSubcategoryUser, 22, http.StatusBadRequest, "email validation not allowed")
)

Error codes related to users

View Source
var (
	ErrDataExportNotAllowed = NewNormalError(NormalSubcategoryDataManagement, 1, http.StatusBadRequest, "data export not allowed")
)

Error codes related to data management

Functions

func GetParameterInvalidCurrencyMessage

func GetParameterInvalidCurrencyMessage(field string) string

GetParameterInvalidCurrencyMessage returns specific error message for invalid currency parameter error

func GetParameterInvalidEmailMessage

func GetParameterInvalidEmailMessage(field string) string

GetParameterInvalidEmailMessage returns specific error message for invalid email parameter error

func GetParameterInvalidHexRGBColorMessage

func GetParameterInvalidHexRGBColorMessage(field string) string

GetParameterInvalidHexRGBColorMessage returns specific error message for invalid hex rgb color parameter error

func GetParameterInvalidMessage

func GetParameterInvalidMessage(field string) string

GetParameterInvalidMessage returns specific error message for invalid parameter error

func GetParameterInvalidUsernameMessage

func GetParameterInvalidUsernameMessage(field string) string

GetParameterInvalidUsernameMessage returns specific error message for invalid username parameter error

func GetParameterIsRequiredMessage

func GetParameterIsRequiredMessage(field string) string

GetParameterIsRequiredMessage returns specific error message for missing parameter error

func GetParameterLengthNotEqualMessage

func GetParameterLengthNotEqualMessage(field string, param string) string

GetParameterLengthNotEqualMessage returns specific error message for parameter length wrong error

func GetParameterMustLessThanCharsMessage

func GetParameterMustLessThanCharsMessage(field string, param string) string

GetParameterMustLessThanCharsMessage returns specific error message for parameter too long error

func GetParameterMustLessThanMessage

func GetParameterMustLessThanMessage(field string, param string) string

GetParameterMustLessThanMessage returns specific error message for parameter too large error

func GetParameterMustMoreThanCharsMessage

func GetParameterMustMoreThanCharsMessage(field string, param string) string

GetParameterMustMoreThanCharsMessage returns specific error message for parameter too short error

func GetParameterMustMoreThanMessage

func GetParameterMustMoreThanMessage(field string, param string) string

GetParameterMustMoreThanMessage returns specific error message for parameter too small error

func GetParameterNotBeBlankMessage

func GetParameterNotBeBlankMessage(field string) string

GetParameterNotBeBlankMessage returns specific error message for blank parameter error

func IsCustomError

func IsCustomError(err error) bool

IsCustomError returns whether this error is defined in this project

Types

type Error

type Error struct {
	Category       ErrorCategory
	SubCategory    int32
	Index          int32
	HttpStatusCode int
	Message        string
	BaseError      []error
	Context        any
}

Error represents the specific error returned to user

func New

func New(category ErrorCategory, subCategory int32, index int32, httpStatusCode int, message string, baseError ...error) *Error

New returns a new error instance

func NewErrorWithContext

func NewErrorWithContext(baseError *Error, context any) *Error

NewErrorWithContext returns a new error instance with specified context

func NewIncompleteOrIncorrectSubmissionError

func NewIncompleteOrIncorrectSubmissionError(err error) *Error

NewIncompleteOrIncorrectSubmissionError returns a new incomplete or incorrect submission error instance

func NewNormalError

func NewNormalError(subCategory int32, index int32, httpStatusCode int, message string) *Error

NewNormalError returns a new normal error instance

func NewSystemError

func NewSystemError(subCategory int32, index int32, httpStatusCode int, message string) *Error

NewSystemError returns a new system error instance

func Or

func Or(err error, defaultErr *Error) *Error

Or would return the error from err parameter if the this error is defined in this project, or return the default error

func (*Error) Code

func (err *Error) Code() int32

Code returns the error code

func (*Error) Error

func (err *Error) Error() string

Error returns the error message

type ErrorCategory

type ErrorCategory int32

ErrorCategory represents error category

const (
	CATEGORY_SYSTEM ErrorCategory = 1
	CATEGORY_NORMAL ErrorCategory = 2
)

Error categories

Jump to

Keyboard shortcuts

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