errors

package
v0.0.0-...-533e1e5 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Error On Cache
	CodeCacheMarshal = Code(iota + 300)
	CodeCacheUnmarshal
	CodeCacheGetSimpleKey
	CodeCacheSetSimpleKey
	CodeCacheDeleteSimpleKey
	CodeCacheSetExpiration
	CodeCacheDecode
	CodeCacheLockNotAcquired
	CodeCacheLockFailed
	CodeCacheInvalidCastType
	CodeCacheNotFound
)
View Source
const (
	// Error On SQL
	CodeSQLBuilder = Code(iota + 700)
	CodeSQLTxBegin
	CodeSQLCreate
	CodeSQLTxCommit
	CodeSQLRead
	CodeSQLRowScan
	CodeSQLCannotRetrieveLastInsertID
)
View Source
const (
	// Code HTTP Handler
	CodeHTTPBadRequest = Code(iota + 900)
	CodeHTTPNotFound
	CodeHTTPInternalServerError
	CodeHTTPUnmarshal
)
View Source
const (
	// Code Domain
	CodeDomain = Code(iota + 2000)
)
View Source
const (
	// Code Usecase
	CodeUsecase = Code(iota + 1000)
)
View Source
const (
	// Error Common
	CodeValueInvalid = Code(iota + 100)
)

Variables

ErrCode extracts the error code from an error.

View Source
var ErrorMessages = ErrorMessage{
	CodeValueInvalid: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeValueInvalid EN`,
		ID:         `Error CodeValueInvalid ID`,
	},
	CodeSQLBuilder: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeSQLBuilder EN`,
		ID:         `Error CodeSQLBuilder ID`,
	},
	CodeSQLTxBegin: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeSQLTxBegin EN`,
		ID:         `Error CodeSQLTxBegin ID`,
	},
	CodeSQLCreate: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeSQLCreate EN`,
		ID:         `Error CodeSQLCreate ID`,
	},
	CodeSQLTxCommit: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeSQLTxCommit EN`,
		ID:         `Error CodeSQLTxCommit ID`,
	},
	CodeSQLCannotRetrieveLastInsertID: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeSQLCannotRetrieveLastInsertID EN`,
		ID:         `Error CodeSQLCannotRetrieveLastInsertID ID`,
	},
	CodeHTTPBadRequest: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeHTTPBadRequest EN`,
		ID:         `Error CodeHTTPBadRequest ID`,
	},
	CodeHTTPNotFound: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeHTTPNotFound EN`,
		ID:         `Error CodeHTTPNotFound ID`,
	},
	CodeHTTPInternalServerError: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeHTTPInternalServerError EN`,
		ID:         `Error CodeHTTPInternalServerError ID`,
	},
	CodeHTTPUnmarshal: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeHTTPUnmarshal EN`,
		ID:         `Error CodeHTTPUnmarshal ID`,
	},
	CodeUsecase: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeUsecase EN`,
		ID:         `Error CodeUsecase ID`,
	},
	CodeDomain: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeDomain EN`,
		ID:         `Error CodeDomain ID`,
	},
	CodeCacheMarshal: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeCacheMarshal EN`,
		ID:         `Error CodeCacheMarshal ID`,
	},
	CodeCacheUnmarshal: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeCacheUnmarshal EN`,
		ID:         `Error CodeCacheUnmarshal ID`,
	},
	CodeCacheGetSimpleKey: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeCacheGetSimpleKey EN`,
		ID:         `Error CodeCacheGetSimpleKey ID`,
	},
	CodeCacheSetSimpleKey: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeCacheSetSimpleKey EN`,
		ID:         `Error CodeCacheSetSimpleKey ID`,
	},
	CodeCacheDeleteSimpleKey: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeCacheDeleteSimpleKey EN`,
		ID:         `Error CodeCacheDeleteSimpleKey ID`,
	},
	CodeCacheSetExpiration: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeCacheSetExpiration EN`,
		ID:         `Error CodeCacheSetExpiration ID`,
	},
	CodeCacheDecode: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeCacheDecode EN`,
		ID:         `Error CodeCacheDecode ID`,
	},
	CodeCacheLockNotAcquired: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeCacheLockNotAcquired EN`,
		ID:         `Error CodeCacheLockNotAcquired ID`,
	},
	CodeCacheLockFailed: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeCacheLockFailed EN`,
		ID:         `Error CodeCacheLockFailed ID`,
	},
	CodeCacheInvalidCastType: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeCacheInvalidCastType EN`,
		ID:         `Error CodeCacheInvalidCastType ID`,
	},
	CodeCacheNotFound: Message{
		StatusCode: http.StatusBadRequest,
		EN:         `Error CodeCacheNotFound EN`,
		ID:         `Error CodeCacheNotFound ID`,
	},
}

TODO: We can change the status and error code as we see fit

New is a drop-in replacement for fmt.Errorf that includes line number information.

NewWithCode is similar to New but also attaches an error code.

Wrap an error to include line number information.

WrapWithCode is similar to Wrap but also attaches an error code.

Wrapf is similar to Wrap but the msg and vals arguments work like the ones for fmt.Errorf.

Functions

This section is empty.

Types

type AppError

type AppError struct {
	Code       Code    `json:"code"`
	Message    string  `json:"message"`
	DebugError *string `json:"debug,omitempty"`
	// contains filtered or unexported fields
}

AppError - Application Error Structure

func Compile

func Compile(service ServiceType, err error, lang string) (int, AppError)

Compile - Get Error Code and HTTP Status Common --> Service --> Default

func (*AppError) Error

func (e *AppError) Error() string

type Code

type Code = stacktrace.ErrorCode

Code - Max value is 4294967295

type ErrorMessage

type ErrorMessage map[Code]Message

ErrorMessage - Mapping Error Code as Human Message

type Message

type Message struct {
	StatusCode    int    `json:"status_code"`
	EN            string `json:"en"`
	ID            string `json:"id"`
	HasAnnotation bool
}

Message - Error Message Support Multi Language

type ServiceType

type ServiceType int
const (
	COMMON ServiceType = 1
)

Jump to

Keyboard shortcuts

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