Documentation
¶
Index ¶
- Variables
- func HandleApiError(c echo.Context, err error, traceID string) error
- func InvalidAccessToken() error
- func NewGrpcError(message string, httpCode int) error
- func ToGrpcError(err error) error
- type ApiHandler
- type AppError
- func ErrFailed(operation string) *AppError
- func ErrNoRowsOrFailed(err error, entity, operation string) *AppError
- func ErrNotFoundResponse(entity string) *AppError
- func NewBadRequestError(message string) *AppError
- func NewConflictError(message string) *AppError
- func NewForbiddenError(message string) *AppError
- func NewInternalError(err error) *AppError
- func NewNotFoundError(resource string) *AppError
- func NewServiceUnavailableError(service string) *AppError
- func NewValidationError(validations []ValidationError) *AppError
- func ParseGrpcError(err error) *AppError
- func (e *AppError) AsRetryable() *AppError
- func (e *AppError) Error() string
- func (e *AppError) Is(target error) bool
- func (e *AppError) Unwrap() error
- func (e *AppError) WithInternal(err error) *AppError
- func (e *AppError) WithMessage(message string) *AppError
- func (e *AppError) WithValidations(validations []ValidationError) *AppError
- type ErrorResponse
- type ErrorType
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadRequest = &AppError{ Type: ErrorTypeBadRequest, Code: http.StatusBadRequest, Message: "Bad request", } ErrValidationFailed = &AppError{ Type: ErrorTypeBadRequest, Code: http.StatusBadRequest, Message: "Validation failed", } Type: ErrorTypeUnauthorized, Code: http.StatusUnauthorized, Message: "Unauthorized", } ErrForbidden = &AppError{ Type: ErrorTypeForbidden, Code: http.StatusForbidden, Message: "Forbidden", } ErrNotFound = &AppError{ Type: ErrorTypeNotFound, Code: http.StatusNotFound, Message: "Resource not found", } ErrConflict = &AppError{ Type: ErrorTypeConflict, Code: http.StatusConflict, Message: "Resource conflict", } ErrTooManyRequests = &AppError{ Type: ErrorTypeBadRequest, Code: http.StatusTooManyRequests, Message: "Too many requests", Retryable: true, } ErrInternal = &AppError{ Type: ErrorTypeInternal, Code: http.StatusInternalServerError, Message: "Internal server error", } Type: ErrorTypeUnavailable, Code: http.StatusServiceUnavailable, Message: "Service unavailable", Retryable: true, } ErrTimeout = &AppError{ Type: ErrorTypeTimeout, Code: http.StatusGatewayTimeout, Message: "Request timeout", Retryable: true, } )
var ErrFindByUserID = ErrNotFound.WithMessage("refresh token not found by user ID")
ErrFindByUserID is a sentinel error for when a refresh token by user ID is not found.
var ErrParseDate = ErrInternal.WithMessage("failed to parse expiration date")
ErrParseDate is returned when parsing the expiration date of a token fails.
var ErrRoleNotFound = ErrNotFound.WithMessage("role not found")
ErrRoleNotFound is a sentinel error for when a role is not found.
var ErrTokenNotFound = ErrNotFound.WithMessage("refresh token not found")
ErrTokenNotFound is a sentinel error for when a refresh token is not found.
var ErrUserNotFound = ErrNotFound.WithMessage("user not found")
ErrUserNotFound is a sentinel error for when a user is not found.
Functions ¶
func InvalidAccessToken ¶
func InvalidAccessToken() error
func NewGrpcError ¶
func ToGrpcError ¶
Types ¶
type ApiHandler ¶
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 ¶
func NewApiHandler(observability observability.TraceLoggerObservability, logger logger.LoggerInterface) ApiHandler
type AppError ¶
type AppError struct {
Type ErrorType `json:"type"`
Code int `json:"-"`
Message string `json:"message"`
Retryable bool `json:"retryable,omitempty"`
Validations []ValidationError `json:"validations,omitempty"`
Internal error `json:"-"`
}
func ErrFailed ¶
ErrFailed creates a generic repository error with the given operation description. This single function replaces dozens of individual error variables across all services.
func ErrNoRowsOrFailed ¶
ErrNoRowsOrFailed maps a mutation error: a "no document/row" not-found error becomes a 404 not-found AppError for the given entity, and any other error becomes a generic failure for the given operation. This avoids leaking a misleading 500 INTERNAL when a mutation targets a record that does not exist (or is in the wrong state).
func ErrNotFoundResponse ¶
ErrNotFoundResponse creates a not-found error response with the given entity name. The entity name should be capitalized (e.g., "User", "Transaction") for proper response formatting. This replaces individual ErrXxxNotFound variables across all services.
func NewBadRequestError ¶
func NewConflictError ¶
func NewForbiddenError ¶
func NewInternalError ¶
func NewNotFoundError ¶
func NewValidationError ¶
func NewValidationError(validations []ValidationError) *AppError
func ParseGrpcError ¶
func (*AppError) AsRetryable ¶
func (*AppError) WithInternal ¶
func (*AppError) WithMessage ¶
func (*AppError) WithValidations ¶
func (e *AppError) WithValidations(validations []ValidationError) *AppError
type ErrorResponse ¶
type ErrorResponse struct {
Status string `json:"status"`
Message string `json:"message"`
Type ErrorType `json:"type,omitempty"`
Code int `json:"code"`
TraceID string `json:"trace_id,omitempty"`
Retryable bool `json:"retryable,omitempty"`
Validations []ValidationError `json:"validations,omitempty"`
}