From db9fa84a998bca03d307fa30e96a9121054cf6de Mon Sep 17 00:00:00 2001 From: SoXX Date: Sun, 25 Aug 2024 00:05:16 +0200 Subject: [PATCH] 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 --- pkg/plug/server.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/plug/server.go b/pkg/plug/server.go index e29fc7a..5fb1a57 100644 --- a/pkg/plug/server.go +++ b/pkg/plug/server.go @@ -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 {