refactor: error handling in Plug.Listen method

- Introduce a new function to create the no data found error
- Simplify error checking logic for clarity and consistency
This commit is contained in:
SoXX 2024-08-25 00:05:16 +02:00
parent eef3296435
commit 6b10ff2766

View File

@ -50,11 +50,16 @@ func (p *Plug) Listen() error {
var err error
var source models.Source
noDataFoundError := otterError.Database{Reason: otterError.NoDataFound}
newDBerr := func() error {
return &otterError.Database{Reason: otterError.NoDataFound}
}
noDataFoundError := newDBerr()
source, err = database.GetSourceByDomain(p.ctx, p.source.Domain)
if err != nil {
if errors.Is(err, &noDataFoundError) {
if errors.Is(err, noDataFoundError) {
log.Printf("Initalizing source!")
source, err = database.CreateSource(p.ctx, p.source)
if err != nil {