Propagate errors from resolveThirdParty
Previously, resolveThirdParty silently swallowed all errors from LoadByOrganizationIDAndCommonThirdPartyID, making real database errors indistinguishable from a missing third party. Now it returns an error for non-not-found failures, wrapped for clarity, and callers log and degrade gracefully. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -118,7 +118,12 @@ func (h *trackerMappingHandler) matchByPattern(
|
|||||||
|
|
||||||
var thirdPartyID *gid.GID
|
var thirdPartyID *gid.GID
|
||||||
if commonPattern.CommonThirdPartyID != nil {
|
if commonPattern.CommonThirdPartyID != nil {
|
||||||
thirdPartyID = h.resolveThirdParty(ctx, conn, tp, &commonPattern)
|
var err error
|
||||||
|
thirdPartyID, err = h.resolveThirdParty(ctx, conn, tp, &commonPattern)
|
||||||
|
if err != nil {
|
||||||
|
h.logger.ErrorCtx(ctx, "cannot resolve third party from pattern match", log.Error(err))
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &commonPattern.ID, thirdPartyID
|
return &commonPattern.ID, thirdPartyID
|
||||||
@@ -165,7 +170,11 @@ func (h *trackerMappingHandler) matchByDomain(
|
|||||||
}
|
}
|
||||||
|
|
||||||
commonPattern.ID = actualID
|
commonPattern.ID = actualID
|
||||||
thirdPartyID := h.resolveThirdParty(ctx, tx, tp, &commonPattern)
|
thirdPartyID, err := h.resolveThirdParty(ctx, tx, tp, &commonPattern)
|
||||||
|
if err != nil {
|
||||||
|
h.logger.ErrorCtx(ctx, "cannot resolve third party from domain match", log.Error(err))
|
||||||
|
return &commonPattern.ID, nil
|
||||||
|
}
|
||||||
|
|
||||||
return &commonPattern.ID, thirdPartyID
|
return &commonPattern.ID, thirdPartyID
|
||||||
}
|
}
|
||||||
@@ -175,9 +184,9 @@ func (h *trackerMappingHandler) resolveThirdParty(
|
|||||||
conn pg.Querier,
|
conn pg.Querier,
|
||||||
tp coredata.TrackerPattern,
|
tp coredata.TrackerPattern,
|
||||||
commonPattern *coredata.CommonTrackerPattern,
|
commonPattern *coredata.CommonTrackerPattern,
|
||||||
) *gid.GID {
|
) (*gid.GID, error) {
|
||||||
if commonPattern.CommonThirdPartyID == nil {
|
if commonPattern.CommonThirdPartyID == nil {
|
||||||
return nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
scope := coredata.NewScopeFromObjectID(tp.ID)
|
scope := coredata.NewScopeFromObjectID(tp.ID)
|
||||||
@@ -190,8 +199,11 @@ func (h *trackerMappingHandler) resolveThirdParty(
|
|||||||
tp.OrganizationID,
|
tp.OrganizationID,
|
||||||
*commonPattern.CommonThirdPartyID,
|
*commonPattern.CommonThirdPartyID,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil
|
if errors.Is(err, coredata.ErrResourceNotFound) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("cannot resolve third party: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &t.ID
|
return &t.ID, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user