Documentation
¶
Index ¶
- Constants
- func AlreadyExistsError(message string, field string) error
- func ConvertProtoValidateError(err error) error
- func ExtractFieldViolations(err error) []*errdetails.BadRequest_FieldViolation
- func FailedPreconditionError(message string) error
- func FieldViolation(field string, err error) *errdetails.BadRequest_FieldViolation
- func FormatValidationError(err error) error
- func GetFieldViolationMessage(err error, field string) string
- func HasFieldViolation(err error, field string) bool
- func InternalError(message string, err error) error
- func InvalidArgumentError(violations []*errdetails.BadRequest_FieldViolation) error
- func IsInternalError(err error) bool
- func IsInvalidArgumentError(err error) bool
- func IsNotFoundError(err error) bool
- func IsPermissionDeniedError(err error) bool
- func IsUnauthenticatedError(err error) bool
- func IsValidationError(err error) bool
- func NewFieldValidationError(field, message string) error
- func NewInternalError(message string, err error) error
- func NewNotFoundError(message string) error
- func NewUnauthenticatedError(message string) error
- func NewValidationError(message string) error
- func NotFoundError(message string) error
- func PermissionDeniedError(message string) error
- func StandardConflictError(resource, reason string) error
- func StandardForbiddenError(message string) error
- func StandardInternalServerError(message string) error
- func StandardNotFoundError(resource string) error
- func StandardUnauthorizedError(message string) error
- func UnauthenticatedError(message string) error
- type ErrorParser
- func (p *ErrorParser) FromFormData(fieldErrors map[string][]string, globalMessage string) *StandardError
- func (p *ErrorParser) ParseBusinessLogicError(errorType ErrorType, message string, field string) *StandardError
- func (p *ErrorParser) ParseConnectError(err error) *StandardError
- func (p *ErrorParser) ParseProtoValidationError(err error) *StandardError
- func (p *ErrorParser) ToFormErrorResponse(err *StandardError) *FormErrorResponse
- func (p *ErrorParser) ValidateEmail(email string, fieldName string) []string
- func (p *ErrorParser) ValidateLength(value string, fieldName string, min, max int) []string
- func (p *ErrorParser) ValidateRange(value int, fieldName string, min, max int) []string
- func (p *ErrorParser) ValidateRequired(value string, fieldName string) []string
- type ErrorType
- type FormErrorResponse
- type StandardError
- type ValidationErrorBuilder
Constants ¶
const ( // Validation error prefix ErrValidationPrefix = "failed to validate request" // Common validation errors ErrEmailAlreadyExists = "email already exists" ErrInvalidResourceName = "invalid resource name" ErrUserNotFound = "user not found" ErrIncorrectCredentials = "incorrect email or password" ErrUserNotActive = "user is not active" ErrTooManyValidationRequests = "too many validation requests" ErrSessionNotFound = "session not found" ErrSessionBlocked = "session is blocked" )
Error message constants
Variables ¶
This section is empty.
Functions ¶
func AlreadyExistsError ¶
AlreadyExistsError creates a gRPC AlreadyExists error
func ConvertProtoValidateError ¶
ConvertProtoValidateError converts a protovalidate error to a gRPC InvalidArgumentError
func ExtractFieldViolations ¶
func ExtractFieldViolations(err error) []*errdetails.BadRequest_FieldViolation
ExtractFieldViolations extracts field violations from an error
func FailedPreconditionError ¶
FailedPreconditionError creates a gRPC FailedPrecondition error
func FieldViolation ¶
func FieldViolation(field string, err error) *errdetails.BadRequest_FieldViolation
FieldViolation creates a field violation for gRPC error details
func FormatValidationError ¶
FormatValidationError formats a validation error with the standard prefix
func GetFieldViolationMessage ¶
GetFieldViolationMessage gets the message for a specific field violation
func HasFieldViolation ¶
HasFieldViolation checks if an error has a field violation for a specific field
func InternalError ¶
InternalError creates a gRPC Internal error
func InvalidArgumentError ¶
func InvalidArgumentError(violations []*errdetails.BadRequest_FieldViolation) error
InvalidArgumentError creates a gRPC InvalidArgument error with field violations
func IsInternalError ¶
IsInternalError checks if an error is an internal error
func IsInvalidArgumentError ¶
IsInvalidArgumentError checks if an error is an invalid argument error
func IsNotFoundError ¶
IsNotFoundError checks if an error is a not found error
func IsPermissionDeniedError ¶
IsPermissionDeniedError checks if an error is a permission denied error
func IsUnauthenticatedError ¶
IsUnauthenticatedError checks if an error is an unauthenticated error
func IsValidationError ¶
IsValidationError checks if an error is a validation error
func NewFieldValidationError ¶
NewFieldValidationError creates a new field validation error with the standard format
func NewInternalError ¶
NewInternalError creates a new internal error with the standard gRPC status
func NewNotFoundError ¶
NewNotFoundError creates a new not found error with the standard gRPC status
func NewUnauthenticatedError ¶
NewUnauthenticatedError creates a new unauthenticated error with the standard gRPC status
func NewValidationError ¶
NewValidationError creates a new validation error with the standard prefix
func NotFoundError ¶
NotFoundError creates a gRPC NotFound error
func PermissionDeniedError ¶
PermissionDeniedError creates a gRPC PermissionDenied error
func StandardConflictError ¶
func StandardForbiddenError ¶
func StandardNotFoundError ¶
Common error builders for consistent error messages
func UnauthenticatedError ¶
UnauthenticatedError creates a gRPC Unauthenticated error
Types ¶
type ErrorParser ¶
type ErrorParser struct{}
ErrorParser provides utilities for parsing and converting different error types
func NewErrorParser ¶
func NewErrorParser() *ErrorParser
NewErrorParser creates a new error parser instance
func (*ErrorParser) FromFormData ¶
func (p *ErrorParser) FromFormData(fieldErrors map[string][]string, globalMessage string) *StandardError
FromFormData creates a validation error from form data This is useful when validating form submissions on the server side
func (*ErrorParser) ParseBusinessLogicError ¶
func (p *ErrorParser) ParseBusinessLogicError(errorType ErrorType, message string, field string) *StandardError
ParseBusinessLogicError creates a business logic error
func (*ErrorParser) ParseConnectError ¶
func (p *ErrorParser) ParseConnectError(err error) *StandardError
ParseConnectError converts Connect-RPC errors to StandardError
func (*ErrorParser) ParseProtoValidationError ¶
func (p *ErrorParser) ParseProtoValidationError(err error) *StandardError
ParseProtoValidationError converts protovalidate errors to StandardError
func (*ErrorParser) ToFormErrorResponse ¶
func (p *ErrorParser) ToFormErrorResponse(err *StandardError) *FormErrorResponse
ToFormErrorResponse converts StandardError to a form-friendly response
func (*ErrorParser) ValidateEmail ¶
func (p *ErrorParser) ValidateEmail(email string, fieldName string) []string
ValidateEmail checks if an email is valid
func (*ErrorParser) ValidateLength ¶
func (p *ErrorParser) ValidateLength(value string, fieldName string, min, max int) []string
ValidateLength checks string length constraints
func (*ErrorParser) ValidateRange ¶
func (p *ErrorParser) ValidateRange(value int, fieldName string, min, max int) []string
ValidateRange checks numeric range constraints
func (*ErrorParser) ValidateRequired ¶
func (p *ErrorParser) ValidateRequired(value string, fieldName string) []string
ValidateRequired checks if a field is required and not empty
type ErrorType ¶
type ErrorType string
ErrorType represents the category of error for consistent handling
const ( // Field-level errors that should be mapped to specific form fields ErrorTypeValidation ErrorType = "VALIDATION_ERROR" // Global errors that should be shown as toasts or general messages ErrorTypeNotFound ErrorType = "NOT_FOUND" ErrorTypeForbidden ErrorType = "FORBIDDEN" ErrorTypeConflict ErrorType = "CONFLICT" ErrorTypeInternal ErrorType = "INTERNAL_ERROR" ErrorTypeRateLimit ErrorType = "RATE_LIMIT" )
type FormErrorResponse ¶
type FormErrorResponse struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
FieldErrors map[string][]string `json:"field_errors,omitempty"`
GlobalError string `json:"global_error,omitempty"`
ErrorType string `json:"error_type,omitempty"`
}
FormErrorResponse represents the structure for frontend error handling
type StandardError ¶
type StandardError struct {
Type ErrorType
Message string
Fields map[string][]string // Field-specific error messages
GlobalError string // Global error message for toasts
Details map[string]string // Additional error details
}
StandardError represents a standardized error structure
func FromConnectError ¶
func FromConnectError(err error) *StandardError
FromConnectError converts a Connect-RPC error to StandardError
func NewGlobalError ¶
func NewGlobalError(errorType ErrorType, message string) *StandardError
NewGlobalError creates a new global error (for toast notifications)
func NewStandardValidationError ¶
func NewStandardValidationError(message string, fieldErrors map[string][]string) *StandardError
NewStandardValidationError creates a new validation error with field mappings
func (*StandardError) AddDetail ¶
func (e *StandardError) AddDetail(key, value string)
AddDetail adds additional error details
func (*StandardError) AddFieldError ¶
func (e *StandardError) AddFieldError(field string, message string)
AddFieldError adds a field-specific error
func (*StandardError) HasFieldErrors ¶
func (e *StandardError) HasFieldErrors() bool
HasFieldErrors returns true if there are field-specific errors
func (*StandardError) HasGlobalError ¶
func (e *StandardError) HasGlobalError() bool
HasGlobalError returns true if there's a global error message
func (*StandardError) ToConnectError ¶
func (e *StandardError) ToConnectError() error
ToConnectError converts StandardError to a Connect-RPC error
type ValidationErrorBuilder ¶
type ValidationErrorBuilder struct {
// contains filtered or unexported fields
}
ValidationErrorBuilder helps build validation errors consistently
func BuildValidationError ¶
func BuildValidationError() *ValidationErrorBuilder
BuildValidationError is a convenience function for building validation errors
func NewValidationErrorBuilder ¶
func NewValidationErrorBuilder(message string) *ValidationErrorBuilder
NewValidationErrorBuilder creates a new validation error builder
func (*ValidationErrorBuilder) AddField ¶
func (b *ValidationErrorBuilder) AddField(field, message string) *ValidationErrorBuilder
AddField adds a field error to the builder
func (*ValidationErrorBuilder) Build ¶
func (b *ValidationErrorBuilder) Build() *StandardError
Build creates the final StandardError
func (*ValidationErrorBuilder) BuildConnectError ¶
func (b *ValidationErrorBuilder) BuildConnectError() error
BuildConnectError creates a Connect-RPC error directly