errorsx

package module
v0.0.0-...-b3a3e34 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 0 Imported by: 1

README

Golang error implementation with an additional information

It can be useful if you need to provide information to error, like place of an error 
(for example, to choose which HTTP code to return based on the error place: validation, business logic, repository), 
states for structured logging and any other information that you may need to be handled with error

Minimal Go version to use: 1.18

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomErr

type CustomErr[T any] interface {
	// Error is a method that returns error text
	Error() string
	// Info is a method that returning additional info for error
	Info() T
}

func NewCustomErr

func NewCustomErr[T any](err string, additionalInf T) CustomErr[T]

NewCustomErr is a custom error constructor Usage:

type ErrInfo struct {
	Critical bool
}
errx := errorsx.NewCustomErr("Message", ErrInfo{
	Critical: false,
})
if errx != nil {
	errInf := errx.Info()
	fmt.Println("Error:", errx.Error())
	fmt.Println("Critical:", errInf.Critical)
}

Directories

Path Synopsis
Package domain_errors provides errors that I use in my applications on the domain layer.
Package domain_errors provides errors that I use in my applications on the domain layer.
Package slog_helpers provides functionality to transform some golang types into a loggable by the package log/slog.
Package slog_helpers provides functionality to transform some golang types into a loggable by the package log/slog.

Jump to

Keyboard shortcuts

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