fix: upsertSource function
now returning the correct source after finding it or creating it
This commit is contained in:
parent
f708706d50
commit
0070352623
@ -14,7 +14,7 @@ func upsertSource(ctx context.Context, source models.Source) (models.Source, err
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
source, err = database.GetSourceByDomain(ctx, source.Domain)
|
localSource, err := database.GetSourceByDomain(ctx, source.Domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == "Database error: NoDataFound" {
|
if err.Error() == "Database error: NoDataFound" {
|
||||||
span.AddEvent("No Source found, initializing source")
|
span.AddEvent("No Source found, initializing source")
|
||||||
@ -32,6 +32,8 @@ func upsertSource(ctx context.Context, source models.Source) (models.Source, err
|
|||||||
span.AddEvent("Source created")
|
span.AddEvent("Source created")
|
||||||
log.WithContext(ctx).WithError(err).WithField("source_domain", source.Domain).WithField("source_id", source.ID).Info("Source created!")
|
log.WithContext(ctx).WithError(err).WithField("source_domain", source.Domain).WithField("source_id", source.ID).Info("Source created!")
|
||||||
|
|
||||||
|
return source, nil
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
span.RecordError(err)
|
span.RecordError(err)
|
||||||
span.SetStatus(codes.Error, err.Error())
|
span.SetStatus(codes.Error, err.Error())
|
||||||
@ -40,5 +42,5 @@ func upsertSource(ctx context.Context, source models.Source) (models.Source, err
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return source, nil
|
return localSource, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user