Help us shape the future of Go! Take the 2026 Go Developer Survey

errorhandler

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound     = errors.New("not found")
	ErrUnauthorized = errors.New("unauthorized")
	ErrForbidden    = errors.New("forbidden")
	ErrInternal     = errors.New("internal error")
)

Define common error types

Functions

func GetLocalizedMessage

func GetLocalizedMessage(code int, lang string) string

GetLocalizedMessage returns the localized error message

Parameters: - code: the error code - lang: the language code

Returns: - string: the localized error message

func InitLogFile

func InitLogFile(logFilePath string) error

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

func NotifyError(err error, recipientEmail string)

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

func Unwrap

func Unwrap(err error) error

Unwrap unwraps an error to get the original error

Parameters: - err: the wrapped error

Returns: - error: the original error

func Wrap

func Wrap(err error, message string) error

Wrap wraps an error with an additional message

Parameters: - err: the original error - message: the additional message

Returns: - error: the wrapped error

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
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL