Documentation
¶
Index ¶
Constants ¶
View Source
const ( // CodeInvalidArgument indicates invalid argument provided CodeInvalidArgument = "invalid_argument" // CodeNotFound indicates resource not found CodeNotFound = "not_found" // CodeAlreadyExists indicates resource already exists CodeAlreadyExists = "already_exists" // CodePermissionDenied indicates permission denied CodePermissionDenied = "permission_denied" // CodeUnauthenticated indicates authentication required CodeUnauthenticated = "unauthenticated" // CodeResourceExhausted indicates resource exhausted (e.g., rate limit) CodeResourceExhausted = "resource_exhausted" // CodeFailedPrecondition indicates precondition failed CodeFailedPrecondition = "failed_precondition" // CodeAborted indicates operation aborted CodeAborted = "aborted" // CodeInternal indicates internal server error CodeInternal = "internal" CodeUnavailable = "unavailable" // CodeValidationFailed indicates validation failed CodeValidationFailed = "validation_failed" )
Common error codes
Variables ¶
This section is empty.
Functions ¶
func IsValidationError ¶
IsValidationError checks if an error is a validation error.
func TranslateError ¶
TranslateError translates an error to a gRPC status error. It handles both structured Error types and standard Go errors.
Types ¶
type Error ¶
type Error struct {
// Code is a machine-readable error code.
Code string
// Message is a human-readable error message.
Message string
// Cause is the underlying error that triggered this error.
Cause error
// Metadata contains additional key-value pairs for context.
Metadata map[string]any
}
Error represents a structured application error.
type ValidationError ¶
ValidationError represents a validation error with field-specific details.
func NewValidationError ¶
func NewValidationError(field, message string) *ValidationError
NewValidationError creates a new validation error for a single field.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface.
type ValidationErrors ¶
type ValidationErrors []ValidationError
ValidationErrors is a collection of validation errors.
func NewValidationErrors ¶
func NewValidationErrors(errors ...ValidationError) ValidationErrors
NewValidationErrors creates a collection of validation errors.
func (ValidationErrors) Error ¶
func (e ValidationErrors) Error() string
Error implements the error interface.
Click to show internal directories.
Click to hide internal directories.