errors

package
v1.0.23 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 13 Imported by: 0

README

Shared Error Definitions

This directory contains centralized error definitions for all domains in the project. It is structured by feature/module to maintain clarity and separation of concerns.

Structure

Each module has its own folder with the following convention:

  • api_<module>_errors.go — for HTTP/API-related errors.
  • repo_<module>_errors.go — for repository/database-related errors.
  • service_<module>_errors.go — for service/business logic-related errors.
  • README.md — brief explanation per module.

This structure allows better error management and decouples concerns between layers (API, Service, Repository).

Modules

  • auth_errors
  • card_errors
  • merchant_errors
  • merchant_document_errors
  • refresh_token_errors
  • role_errors
  • saldo_errors
  • topup_errors
  • transaction_errors
  • transfer_errors
  • user_errors
  • user_role_errors
  • withdraw_errors

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadRequest = &AppError{
		Code:    http.StatusBadRequest,
		Message: "Bad request",
	}

	ErrValidationFailed = &AppError{
		Code:    http.StatusBadRequest,
		Message: "Validation failed",
	}

	ErrUnauthorized = &AppError{
		Code:    http.StatusUnauthorized,
		Message: "Unauthorized",
	}

	ErrForbidden = &AppError{
		Code:    http.StatusForbidden,
		Message: "Forbidden",
	}

	ErrNotFound = &AppError{
		Code:    http.StatusNotFound,
		Message: "Resource not found",
	}

	ErrConflict = &AppError{
		Code:    http.StatusConflict,
		Message: "Resource conflict",
	}

	ErrTooManyRequests = &AppError{
		Code:      http.StatusTooManyRequests,
		Message:   "Too many requests",
		Retryable: true,
	}

	ErrInternal = &AppError{
		Code:    http.StatusInternalServerError,
		Message: "Internal server error",
	}

	ErrServiceUnavailable = &AppError{
		Code:      http.StatusServiceUnavailable,
		Message:   "Service unavailable",
		Retryable: true,
	}

	ErrTimeout = &AppError{
		Code:      http.StatusGatewayTimeout,
		Message:   "Request timeout",
		Retryable: true,
	}
)

Functions

func HandleApiError added in v1.0.16

func HandleApiError(c echo.Context, err error, traceID string) error

func InvalidAccessToken added in v1.0.16

func InvalidAccessToken() error

func NewGrpcError added in v1.0.16

func NewGrpcError(message string, httpCode int) error

func ToGrpcError added in v1.0.16

func ToGrpcError(err error) error

GrpcErrorToJson takes a pointer to a gRPC ErrorResponse and returns a string containing the JSON representation of the error.

The function does not return an error and instead panics if the marshaling fails.

Types

type ApiHandler added in v1.0.16

type ApiHandler interface {
	Handle(method string, handler func(echo.Context) error) echo.HandlerFunc
	HandleApiErrorWithTracing(c echo.Context, err error, span trace.Span, method string) error
}

func NewApiHandler added in v1.0.16

func NewApiHandler(observability observability.TraceLoggerObservability, logger logger.LoggerInterface) ApiHandler

type AppError added in v1.0.16

type AppError struct {
	Code        int               `json:"-"`
	Message     string            `json:"message"`
	Retryable   bool              `json:"retryable,omitempty"`
	Validations []ValidationError `json:"validations,omitempty"`
	Internal    error             `json:"-"`
}

func NewBadRequestError added in v1.0.16

func NewBadRequestError(message string) *AppError

func NewConflictError added in v1.0.16

func NewConflictError(message string) *AppError

func NewErrorResponse added in v1.0.16

func NewErrorResponse(message string, code int) *AppError

func NewInternalError added in v1.0.16

func NewInternalError(err error) *AppError

func NewNotFoundError added in v1.0.16

func NewNotFoundError(resource string) *AppError

func NewServiceUnavailableError added in v1.0.16

func NewServiceUnavailableError(service string) *AppError

func NewValidationError added in v1.0.16

func NewValidationError(validations []ValidationError) *AppError

func (*AppError) AsRetryable added in v1.0.16

func (e *AppError) AsRetryable() *AppError

func (*AppError) Error added in v1.0.16

func (e *AppError) Error() string

func (*AppError) Unwrap added in v1.0.16

func (e *AppError) Unwrap() error

func (*AppError) WithInternal added in v1.0.16

func (e *AppError) WithInternal(err error) *AppError

func (*AppError) WithMessage added in v1.0.16

func (e *AppError) WithMessage(message string) *AppError

func (*AppError) WithValidations added in v1.0.16

func (e *AppError) WithValidations(validations []ValidationError) *AppError

type ErrorResponse added in v1.0.16

type ErrorResponse struct {
	Status      string            `json:"status"`
	Message     string            `json:"message"`
	Code        int               `json:"code"`
	TraceID     string            `json:"trace_id,omitempty"`
	Retryable   bool              `json:"retryable,omitempty"`
	Validations []ValidationError `json:"validations,omitempty"`
}

type ValidationError added in v1.0.16

type ValidationError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

Directories

Path Synopsis
card_errors
merchant_document_errors
merchant_errors
refresh_token_errors
role_errors
saldo_errors
topup_errors
transaction_errors
transfer_errors
user_errors
user_role_errors
withdraw_errors

Jump to

Keyboard shortcuts

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