Documentation
¶
Overview ¶
Package errors provides error handling utilities for the servicelib package.
Package errors provides a comprehensive error handling system for the application. It includes error codes, HTTP status mapping, contextual information, and utilities for creating, wrapping, and serializing errors.
Index ¶
- Constants
- Variables
- func As(err error, target interface{}) bool
- func DetectErrorFromContext(ctx context.Context) error
- func DetectErrorType(err error) string
- func FormatErrorWithSource(err error, source string) string
- func GetHTTPStatus(err error) int
- func Is(err, target error) bool
- func IsApplicationError(err error) bool
- func IsAuthenticationError(err error) bool
- func IsAuthorizationError(err error) bool
- func IsBusinessRuleError(err error) bool
- func IsCancelled(err error) bool
- func IsConfigurationError(err error) bool
- func IsContextError(err error) bool
- func IsDatabaseError(err error) bool
- func IsDomainError(err error) bool
- func IsExternalServiceError(err error) bool
- func IsInfrastructureError(err error) bool
- func IsNetworkError(err error) bool
- func IsNotFoundError(err error) bool
- func IsRetryError(err error) bool
- func IsTimeout(err error) bool
- func IsTransientError(err error) bool
- func IsValidationError(err error) bool
- func New(code ErrorCode, message string) error
- func ToJSON(err error) string
- func Unwrap(err error) error
- func Wrap(err error, code ErrorCode, message string) error
- func WrapWithDetails(err error, code ErrorCode, message string, details map[string]interface{}) error
- func WrapWithOperation(err error, code ErrorCode, message string, operation string) error
- type ApplicationError
- type AuthenticationError
- type AuthorizationError
- type BaseError
- type BusinessRuleError
- type ConfigurationError
- type ContextError
- type DatabaseError
- type DomainError
- type ErrorCode
- type ExternalServiceError
- type InfrastructureError
- type NetworkError
- type NotFoundError
- type RetryError
- type ValidationError
- type ValidationErrors
Constants ¶
const ( NotFoundCode = core.NotFoundCode InvalidInputCode = core.InvalidInputCode DatabaseErrorCode = core.DatabaseErrorCode InternalErrorCode = core.InternalErrorCode TimeoutCode = core.TimeoutCode CanceledCode = core.CanceledCode AlreadyExistsCode = core.AlreadyExistsCode ForbiddenCode = core.ForbiddenCode ValidationErrorCode = core.ValidationErrorCode BusinessRuleViolationCode = core.BusinessRuleViolationCode ExternalServiceErrorCode = core.ExternalServiceErrorCode NetworkErrorCode = core.NetworkErrorCode ConfigurationErrorCode = core.ConfigurationErrorCode ResourceExhaustedCode = core.ResourceExhaustedCode DataCorruptionCode = core.DataCorruptionCode ConcurrencyErrorCode = core.ConcurrencyErrorCode )
Error code constants
Variables ¶
var ( ErrNotFound = core.NewBaseError(NotFoundCode, "resource not found", nil) ErrInvalidInput = core.NewBaseError(InvalidInputCode, "invalid input", nil) ErrInternal = core.NewBaseError(InternalErrorCode, "internal error", nil) ErrForbidden = core.NewBaseError(ForbiddenCode, "forbidden", nil) ErrTimeout = core.NewBaseError(TimeoutCode, "operation timed out", nil) ErrCanceled = core.NewBaseError(CanceledCode, "operation canceled", nil) ErrAlreadyExists = core.NewBaseError(AlreadyExistsCode, "resource already exists", nil) )
Standard errors
Functions ¶
func DetectErrorFromContext ¶ added in v1.5.0
DetectErrorFromContext extracts an error from a context if present
func DetectErrorType ¶ added in v1.5.0
DetectErrorType returns a string describing the type of error
func FormatErrorWithSource ¶ added in v1.5.0
FormatErrorWithSource formats an error with its source information
func GetHTTPStatus ¶
GetHTTPStatus returns the HTTP status code for an error.
func IsApplicationError ¶
func IsAuthenticationError ¶ added in v1.4.0
func IsAuthorizationError ¶ added in v1.4.0
func IsBusinessRuleError ¶ added in v1.4.0
func IsCancelled ¶
IsCancelled checks if an error is a cancellation error.
func IsConfigurationError ¶ added in v1.4.0
func IsContextError ¶ added in v1.5.0
func IsDatabaseError ¶ added in v1.4.0
func IsDomainError ¶ added in v1.4.0
Error type checking functions
func IsExternalServiceError ¶ added in v1.4.0
func IsInfrastructureError ¶ added in v1.4.0
func IsNetworkError ¶ added in v1.4.0
func IsNotFoundError ¶
func IsRetryError ¶ added in v1.5.0
func IsTransientError ¶ added in v1.5.0
IsTransientError checks if an error is a transient error that may be resolved by retrying.
func IsValidationError ¶
Types ¶
type ApplicationError ¶
type ApplicationError = app.ApplicationError
Error type aliases
func NewApplicationError ¶
func NewApplicationError(code ErrorCode, message string, cause error) *ApplicationError
Application error creation functions
type AuthenticationError ¶ added in v1.4.0
type AuthenticationError = app.AuthenticationError
Error type aliases
func NewAuthenticationError ¶ added in v1.4.0
func NewAuthenticationError(message string, username string, cause error) *AuthenticationError
type AuthorizationError ¶ added in v1.4.0
type AuthorizationError = app.AuthorizationError
Error type aliases
func NewAuthorizationError ¶ added in v1.4.0
type BusinessRuleError ¶ added in v1.4.0
type BusinessRuleError = domain.BusinessRuleError
Error type aliases
func NewBusinessRuleError ¶ added in v1.4.0
func NewBusinessRuleError(message string, rule string, cause error) *BusinessRuleError
type ConfigurationError ¶ added in v1.4.0
type ConfigurationError = app.ConfigurationError
Error type aliases
func NewConfigurationError ¶ added in v1.4.0
func NewConfigurationError(message string, configKey string, configValue string, cause error) *ConfigurationError
type ContextError ¶ added in v1.5.0
type ContextError = infra.ContextError
Error type aliases
func NewContextError ¶ added in v1.5.0
func NewContextError(message string, cause error) *ContextError
type DatabaseError ¶ added in v1.4.0
type DatabaseError = infra.DatabaseError
Error type aliases
func NewDatabaseError ¶ added in v1.4.0
func NewDatabaseError(message string, operation string, table string, cause error) *DatabaseError
type DomainError ¶
type DomainError = domain.DomainError
Error type aliases
func NewDomainError ¶
func NewDomainError(code ErrorCode, message string, cause error) *DomainError
Domain error creation functions
type ExternalServiceError ¶ added in v1.4.0
type ExternalServiceError = infra.ExternalServiceError
Error type aliases
func NewExternalServiceError ¶ added in v1.4.0
func NewExternalServiceError(message string, serviceName string, endpoint string, cause error) *ExternalServiceError
type InfrastructureError ¶ added in v1.4.0
type InfrastructureError = infra.InfrastructureError
Error type aliases
func NewInfrastructureError ¶ added in v1.4.0
func NewInfrastructureError(code ErrorCode, message string, cause error) *InfrastructureError
Infrastructure error creation functions
type NetworkError ¶ added in v1.4.0
type NetworkError = infra.NetworkError
Error type aliases
func NewNetworkError ¶ added in v1.4.0
func NewNetworkError(message string, host string, port string, cause error) *NetworkError
type NotFoundError ¶
type NotFoundError = domain.NotFoundError
Error type aliases
func NewNotFoundError ¶
func NewNotFoundError(resourceType string, resourceID string, cause error) *NotFoundError
type RetryError ¶ added in v1.5.0
type RetryError = infra.RetryError
Error type aliases
func NewRetryError ¶ added in v1.5.0
func NewRetryError(message string, cause error, attempts int, maxAttempts int) *RetryError
type ValidationError ¶
type ValidationError = domain.ValidationError
Error type aliases
func NewValidationError ¶
func NewValidationError(message string, field string, cause error) *ValidationError
type ValidationErrors ¶
type ValidationErrors = domain.ValidationErrors
Error type aliases
func NewValidationErrors ¶
func NewValidationErrors(message string, errors ...*ValidationError) *ValidationErrors
Directories
¶
| Path | Synopsis |
|---|---|
|
Package app provides application-level error types for the application.
|
Package app provides application-level error types for the application. |
|
Package core provides the core error handling functionality for the application.
|
Package core provides the core error handling functionality for the application. |
|
Package domain provides domain-specific error types for the application.
|
Package domain provides domain-specific error types for the application. |
|
Package http provides HTTP-related error utilities for the application.
|
Package http provides HTTP-related error utilities for the application. |
|
Package infra provides infrastructure-related error types for the application.
|
Package infra provides infrastructure-related error types for the application. |
|
Package log provides logging integration for the error handling system.
|
Package log provides logging integration for the error handling system. |
|
Package metrics provides metrics integration for the error handling system.
|
Package metrics provides metrics integration for the error handling system. |
|
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
|
Package trace provides tracing integration for the error handling system.
|
Package trace provides tracing integration for the error handling system. |
|
Package types provides specific error types for the errors package.
|
Package types provides specific error types for the errors package. |