Documentation ¶
Overview ¶
Package domain_errors provides errors that I use in my applications on the domain layer. Those errors are easy to handle and use on the API layer. Those errors have information about HTTP code, log it or not, api message, any additional states. Also, this package provides some
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HttpHandleDomainErr ¶
func HttpHandleDomainErr( dErr DomainErr, logger *slog.Logger, w http.ResponseWriter, r *http.Request)
HttpHandleDomainErr handles domain error for you in http handler. Just pass values and it sets http body, http code and logs the error if err.Info().Log is true.
This function don't check if logger or error or request is nil. Check it before using this function in your code. Overwise you'll get a panic
Usage:
... // Somewhere inside the http handler someData, errx := domain.SomeLogic( ... ) if errx != nil { HttpHandleDomainErr(errx, logger, w, r) return }
func LogDomainErr ¶
Just logs error if err.Info().Log is true It don't check if logger or error is nil. Check it before using this function in your code. Overwise this function will panic
Types ¶
type DomainErr ¶
type DomainErr errorsx.CustomErr[DomainErrInfo]
DomainErr is an error that is great for structured logging due it's ability to store any map of data and it contains information about how to handle it What makes it a perfect choise for using on the domain layer of the application That error can be easily handled using LogDomainErr and HttpHandleDomainErr functions
func NewDomainErr ¶
func NewDomainErr(err string, inf DomainErrInfo) DomainErr
NewDomainErr create an error that is great for structured logging and contains information about how to handle it (log it or not, how handle this error on API layer)