helper

package
v0.0.0-...-0aa3dee Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Token
	UnExpectedError = "unexpected error"
	ClaimsNotFound  = "claims not found"
	TokenRequired   = "token required"
	TokenExpired    = "token expired"
	TokenInvalid    = "token invalid"

	// User
	PermissionDenied = "Permission denied"

	// DB
	RecordNotFound = "record not found"
)

Variables

View Source
var StatusCodeMapping = map[string]int{

	RecordNotFound: 400,
}

Functions

func TranslateErrorToStatusCode

func TranslateErrorToStatusCode(err error) int

func ValidateStruct

func ValidateStruct[Td any](dto *Td) error

Types

type BaseHttpResponse

type BaseHttpResponse struct {
	Result           any                `json:"result"`
	Success          bool               `json:"success"`
	ResultCode       ResultCode         `json:"resultCode"`
	ValidationErrors *[]ValidationError `json:"validationErrors"`
	Error            any                `json:"error"`
}

func GenerateBaseResponse

func GenerateBaseResponse(result any, success bool, resultCode ResultCode) *BaseHttpResponse

func GenerateBaseResponseWithAnyError

func GenerateBaseResponseWithAnyError(result any, success bool, resultCode ResultCode, err any) *BaseHttpResponse

func GenerateBaseResponseWithError

func GenerateBaseResponseWithError(result any, success bool, resultCode ResultCode, err error) *BaseHttpResponse

func GenerateBaseResponseWithValidationError

func GenerateBaseResponseWithValidationError(result any, success bool, resultCode ResultCode, err error) *BaseHttpResponse

type ResultCode

type ResultCode int
const (
	Success             ResultCode = 0
	BadRequestError     ResultCode = 40000
	ValidationErrorCode ResultCode = 40001
	NotFoundError       ResultCode = 40401
	CustomRecovery      ResultCode = 50001
	InternalError       ResultCode = 50002
	DBConnectionError   ResultCode = 50003
)

type ServiceError

type ServiceError struct {
	EndUserMessage   string `json:"endUserMessage"`
	TechnicalMessage string `json:"technicalMessage"`
	Err              error
}

func (*ServiceError) Error

func (s *ServiceError) Error() string

type ValidationError

type ValidationError struct {
	Property string `json:"property"`
	Tag      string `json:"tag"`
	Value    string `json:"value"`
}

Jump to

Keyboard shortcuts

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