fix(error): Refactor error handling to use errors.Is for more robust database error checking in Listen method.

This commit is contained in:
SoXX 2024-08-24 23:42:38 +02:00
parent 27e14a03c9
commit 22dfd5a5ad

View File

@ -3,6 +3,7 @@ package plug
import (
"context"
"fmt"
"github.com/pkg/errors"
"log"
"net"
@ -51,9 +52,10 @@ func (p *Plug) Listen() error {
source, err = database.GetSourceByDomain(p.ctx, p.source.Domain)
if err != nil {
if err.Error() == otterError.NoDataFound {
if errors.Is(err, &otterError.Database{Reason: otterError.NoDataFound}) {
log.Printf("Initalizing source!")
if source, err = database.CreateSource(p.ctx, p.source); err != nil {
source, err = database.CreateSource(p.ctx, p.source)
if err != nil {
panic(err)
}
} else {