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
eef3296435
commit
6b10ff2766
@ -50,11 +50,16 @@ func (p *Plug) Listen() error {
|
|||||||
var err error
|
var err error
|
||||||
var source models.Source
|
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)
|
source, err = database.GetSourceByDomain(p.ctx, p.source.Domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, &noDataFoundError) {
|
|
||||||
|
if errors.Is(err, noDataFoundError) {
|
||||||
log.Printf("Initalizing source!")
|
log.Printf("Initalizing source!")
|
||||||
source, err = database.CreateSource(p.ctx, p.source)
|
source, err = database.CreateSource(p.ctx, p.source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user