Documentation
¶
Index ¶
- Variables
- func GetLocalizedMessage(code int, lang string) string
- func InitLogFile(logFilePath string) error
- func LogError(err error)
- func NotifyError(err error, recipientEmail string)
- func RegisterErrorHandler(handler ErrorHandler)
- func TriggerCustomErrorHandlers(err error)
- func Unwrap(err error) error
- func Wrap(err error, message string) error
- type AggregateError
- type CustomError
- type ErrorHandler
- type ErrorLevel
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrForbidden = errors.New("forbidden") ErrInternal = errors.New("internal error") )
Define common error types
Functions ¶
func GetLocalizedMessage ¶
GetLocalizedMessage returns the localized error message
Parameters: - code: the error code - lang: the language code
Returns: - string: the localized error message
func InitLogFile ¶
InitLogFile initializes the log file
Parameters: - logFilePath: the path to the log file
Returns: - error: an error if the log file could not be initialized, otherwise nil
func LogError ¶
func LogError(err error)
LogError logs the error to both file and console
Parameters: - err: the error to log
func NotifyError ¶
NotifyError sends an error notification (example: send email)
Parameters: - err: the error to notify about - recipientEmail: the recipient email address
func RegisterErrorHandler ¶
func RegisterErrorHandler(handler ErrorHandler)
RegisterErrorHandler registers a custom error handler
Parameters: - handler: the custom error handler to register
func TriggerCustomErrorHandlers ¶
func TriggerCustomErrorHandlers(err error)
TriggerCustomErrorHandlers triggers all registered custom error handlers
Parameters: - err: the error to handle
Types ¶
type AggregateError ¶
type AggregateError struct {
Errors []error
}
AggregateError aggregates multiple errors into one
func NewAggregateError ¶
func NewAggregateError(errors []error) *AggregateError
NewAggregateError creates a new AggregateError
Parameters: - errors: the list of errors to aggregate
Returns: - *AggregateError: the new AggregateError
func (*AggregateError) Error ¶
func (e *AggregateError) Error() string
Error returns the aggregated error message
Returns: - string: the aggregated error message
type CustomError ¶
type CustomError struct { Code int // Error code Message string // Error message Level ErrorLevel // Error level Context interface{} // Context information Original error // Original error }
CustomError represents a custom error type
func NewError ¶
func NewError(code int, message string, level ErrorLevel, context interface{}, original error) *CustomError
NewError creates a new custom error
Parameters: - code: the error code - message: the error message - level: the error level - context: the context information - original: the original error
Returns: - *CustomError: the new custom error
func (*CustomError) Error ¶
func (e *CustomError) Error() string
Error returns the error message for the CustomError
Returns: - string: the formatted error message
type ErrorHandler ¶
type ErrorHandler interface {
HandleError(err error)
}
ErrorHandler is an interface for custom error handlers
type ErrorLevel ¶
type ErrorLevel int
ErrorLevel represents the severity level of an error
const ( Info ErrorLevel = iota Warning Error Critical )