customerror

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equals

func Equals(left, right error) bool

Equals check if input values are equals

func Log

func Log(log *zap.SugaredLogger, err error)

Log log error according to error class.

func NewError

func NewError(err error, msg string, code Code) error

NewError is constructor for error custom errors.

func NewFailure

func NewFailure(err error, f Failure) error

NewFailure is constructor for failure custom errors.

func NewRequestValidationFailure

func NewRequestValidationFailure(desc string, data map[string]interface{}) error

NewRequestValidationFailure is constructor for request validation failure custom errors.

func NewResponseValidationFailure

func NewResponseValidationFailure(desc string, data map[string]interface{}) error

NewResponseValidationFailure is constructor for response validation failure custom errors.

func NewToolkitFailure

func NewToolkitFailure(err error, desc string) error

NewToolkitFailure is constructor for toolkit failure custom errors.

Types

type Class

type Class uint32

Class is type of error class.

const (
	// FailureClass is failure error class constant.
	FailureClass Class = iota + 1
	// ErrorClass is error error class constant.
	ErrorClass
)

type Code

type Code uint32

Code is type for error code.

const (
	// DefaultErrorCode is DefaultError code.
	DefaultErrorCode Code = 5000
	// PostgreSQLErrorCode is PostgreSQLError code.
	PostgreSQLErrorCode Code = 5001
	// RedisErrorCode is RedisError code.
	RedisErrorCode Code = 5002
	// ToolkitErrorCode is ToolkitError code.
	ToolkitErrorCode Code = 5003
	// CryptoGenerationErrorCode is error code for generation crypto.
	CryptoGenerationErrorCode Code = 5004
	// CryptoEncryptErrorCode is encrypt error code.
	CryptoEncryptErrorCode Code = 5005
	// CryptoDecryptErrorCode is decrypt error code.
	CryptoDecryptErrorCode Code = 5006
	// DefaultCryptoErrorCode is default crypto error code.
	DefaultCryptoErrorCode Code = 5007
	// RSAKeyFilesNotFoundErrorCode is RSAKeyFilesNotFoundError code
	RSAKeyFilesNotFoundErrorCode Code = 5008
	// NotImplementedErrorCode is NotImplementedError code.
	NotImplementedErrorCode Code = 5011
	// OAuthManagementAPIServiceUnavailableErrorCode is OAuthManagementAPIServiceUnavailableError code.
	OAuthManagementAPIServiceUnavailableErrorCode Code = 5031
	// UserManagementAPIServiceUnavailableErrorCode is UserManagementAPIServiceUnavailableError code.
	UserManagementAPIServiceUnavailableErrorCode Code = 5032
	// ColangAPIServiceUnavailableErrorCode is ColangAPIServiceUnavailableError code.
	ColangAPIServiceUnavailableErrorCode Code = 5033
	// WorldAPIServiceUnavailableErrorCode is WorldAPIServiceUnavailableError code.
	WorldAPIServiceUnavailableErrorCode Code = 5034
	// AdminAPIServiceUnavailableErrorCode is AdminAPIServiceUnavailableError code.
	AdminAPIServiceUnavailableErrorCode Code = 5035
	// SecretsManagementAPIServiceUnavailableErrorCode is SecretsManagementAPIServiceUnavailableError code.
	SecretsManagementAPIServiceUnavailableErrorCode Code = 5036
	// RequestValidationFailureCode is RequestValidationFailure code.
	RequestValidationFailureCode Code = 4001
	// ResponseValidationFailureCode is ResponseValidationFailure code.
	ResponseValidationFailureCode Code = 4002
	// OAuthManagementAPIBadRequestCode is OAuthManagementAPIBadRequest code.
	OAuthManagementAPIBadRequestCode Code = 4003
	// UserManagementAPIBadRequestCode is UserManagementAPIBadRequest code.
	UserManagementAPIBadRequestCode Code = 4004
	// ColangAPIServiceBadRequestCode is ColangAPIServiceBadRequest code.
	ColangAPIServiceBadRequestCode Code = 4005
	// WorldAPIServiceBadRequestCode is WorldAPIServiceBadRequest code.
	WorldAPIServiceBadRequestCode Code = 4006
	// AdminAPIServiceBadRequestCode is AdminAPIServiceBadRequest code.
	AdminAPIServiceBadRequestCode Code = 4007
	// SecretsManagementAPBadRequestCode is SecretsManagementAPBadRequest code.
	SecretsManagementAPBadRequestCode Code = 4008
	// TokenIsInvalidFailureCode is TokenIsInvalidFailure code.
	TokenIsInvalidFailureCode Code = 4011
	// TokenIsExpiredFailureCode is TokenIsExpiredFailure code.
	TokenIsExpiredFailureCode Code = 4012
	// IncorrectTokenFormatFailureCode is IncorrectTokenFormat code.
	IncorrectTokenFormatFailureCode Code = 4013
	// RoleForbiddenFailureCode is RoleForbiddenFailure code.
	RoleForbiddenFailureCode Code = 4031
	// EntityNotFoundFailureCode is EntityNotFoundFailure code.
	EntityNotFoundFailureCode Code = 4041
	// HTTPMethodNotAllowedFailureCode is HTTPMethodNotAllowedFailure code.
	HTTPMethodNotAllowedFailureCode Code = 4051
	// EntityAlreadyExistsFailureCode is EntityAlreadyExistsFailure code.
	EntityAlreadyExistsFailureCode Code = 4091
	// ExtractIPAddressFromRequestFailureCode is ExtractIPAddressFromRequestFailure code.
	ExtractIPAddressFromRequestFailureCode Code = 4003
)

func (Code) UInt32

func (c Code) UInt32() uint32

UInt32 converts code to uint32.

type CustomError

type CustomError struct {
	Class       Class   `json:"class"`
	Fail        Failure `json:"failure"`
	Err         Error   `json:"error"`
	ExtendedErr *CustomError
}

CustomError is union of error & failure.

func Cast

func Cast(err error) *CustomError

Cast cases error into *CustomError. If input is not *CustomError it will creates new *CustomError.

func CastStrict

func CastStrict(err error) *CustomError

CastStrict cases error into *CustomError. If input is not *CustomError it will returns <nil>.

func (*CustomError) Error

func (ce *CustomError) Error() string

Error is method that allows *CustomError matches with error interface.

type Error

type Error struct {
	Message string `json:"message"`
	Code    Code   `json:"code"`
}

Error is struct that represents error with status code 5XX.

type Failure

type Failure struct {
	Code        Code                   `json:"code"`
	Message     string                 `json:"message"`
	Description string                 `json:"description"`
	StatusCode  int                    `json:"status_code" desc:"StatusCode is HTTP status code"`
	Data        map[string]interface{} `json:"data"`
}

Failure is struct that represents error with status code 4XX. It is expected error.

Jump to

Keyboard shortcuts

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