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:
parent
772ee38e0b
commit
db9fa84a99
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user