utils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorMapper = map[ErrorType]CustomErrorMap{
		ErrNotFound:           {BusinessErrorCode: 101, HttpStatusCode: http.StatusNotFound, Origin: ErrNotFound},
		ErrForbidden:          {BusinessErrorCode: 102, HttpStatusCode: http.StatusForbidden, Origin: ErrForbidden},
		ErrBadRequest:         {BusinessErrorCode: 103, HttpStatusCode: http.StatusBadRequest, Origin: ErrBadRequest},
		ErrQueryRead:          {BusinessErrorCode: 104, HttpStatusCode: http.StatusInternalServerError, Origin: ErrQueryRead},
		ErrQueryScan:          {BusinessErrorCode: 105, HttpStatusCode: http.StatusInternalServerError, Origin: ErrQueryScan},
		ErrQueryTxBegin:       {BusinessErrorCode: 106, HttpStatusCode: http.StatusInternalServerError, Origin: ErrQueryTxBegin},
		ErrQueryTxInsert:      {BusinessErrorCode: 107, HttpStatusCode: http.StatusInternalServerError, Origin: ErrQueryTxInsert},
		ErrQueryTxUpdate:      {BusinessErrorCode: 108, HttpStatusCode: http.StatusInternalServerError, Origin: ErrQueryTxUpdate},
		ErrQueryTxDelete:      {BusinessErrorCode: 109, HttpStatusCode: http.StatusInternalServerError, Origin: ErrQueryTxDelete},
		ErrQueryTxCommit:      {BusinessErrorCode: 110, HttpStatusCode: http.StatusInternalServerError, Origin: ErrQueryTxCommit},
		ErrInvalidContentType: {BusinessErrorCode: 111, HttpStatusCode: http.StatusBadRequest, Origin: ErrInvalidContentType},
	}
)

Functions

func GenerateUUID

func GenerateUUID() string

GenerateUUID to generate random uuid.

func GetValidatorFieldError

func GetValidatorFieldError(err error) map[string]string

func ValidateStruct

func ValidateStruct(req interface{}) error

Types

type Causer

type Causer interface {
	Cause() error
}

type CustomErrorMap

type CustomErrorMap struct {
	BusinessErrorCode int
	HttpStatusCode    int
	Origin            error
}

type ErrorStage

type ErrorStage string
var (
	ERROR_REPOSITORY_STAGE ErrorStage = "repository"
	ERROR_USE_CASE_STAGE   ErrorStage = "usecase"
	ERROR_HANDLER_STAGE    ErrorStage = "handler"
	ERROR_INFRA_STAGE      ErrorStage = "infra"
)

type ErrorType

type ErrorType error
var (
	ErrNotFound      ErrorType = errors.New("data not found")
	ErrForbidden     ErrorType = errors.New("forbidden access")
	ErrBadRequest    ErrorType = errors.New("bad request")
	ErrQueryRead     ErrorType = errors.New("error while querying storage")
	ErrQueryScan     ErrorType = errors.New("error while scan query result")
	ErrQueryTxBegin  ErrorType = errors.New("error while preparing query transaction")
	ErrQueryTxInsert ErrorType = errors.New("error while inserting record")
	ErrQueryTxUpdate ErrorType = errors.New("error while updating record")
	ErrQueryTxDelete ErrorType = errors.New("error while deleting record")
	ErrQueryTxCommit ErrorType = errors.New("error while committing record changes")

	ErrInvalidContentType = errors.New("invalid content type")
)

type ErrorWithCode

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

func NewErrorWithCode

func NewErrorWithCode(c int, e error) *ErrorWithCode

func (*ErrorWithCode) Cause

func (err *ErrorWithCode) Cause() error

func (*ErrorWithCode) Code

func (err *ErrorWithCode) Code() int

func (*ErrorWithCode) Error

func (err *ErrorWithCode) Error() string

Jump to

Keyboard shortcuts

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