diff --git a/pkg/coredata/trust_center_access.go b/pkg/coredata/trust_center_access.go index ec4cc342c..9195de6c0 100644 --- a/pkg/coredata/trust_center_access.go +++ b/pkg/coredata/trust_center_access.go @@ -16,6 +16,7 @@ package coredata import ( "context" + "errors" "fmt" "maps" "time" @@ -39,8 +40,16 @@ type ( } TrustCenterAccesses []*TrustCenterAccess + + ErrTrustCenterAccessNotFound struct { + Identifier string + } ) +func (e ErrTrustCenterAccessNotFound) Error() string { + return fmt.Sprintf("trust center access not found: %s", e.Identifier) +} + func (tca *TrustCenterAccess) CursorKey(orderBy TrustCenterAccessOrderField) page.CursorKey { switch orderBy { case TrustCenterAccessOrderFieldCreatedAt: @@ -86,6 +95,10 @@ LIMIT 1; access, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[TrustCenterAccess]) if err != nil { + if errors.Is(err, pgx.ErrNoRows) { + return &ErrTrustCenterAccessNotFound{Identifier: accessID.String()} + } + return fmt.Errorf("cannot collect trust center access: %w", err) } @@ -135,6 +148,10 @@ LIMIT 1; access, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[TrustCenterAccess]) if err != nil { + if errors.Is(err, pgx.ErrNoRows) { + return &ErrTrustCenterAccessNotFound{Identifier: fmt.Sprintf("trust_center_id=%s, email=%s", trustCenterID, email)} + } + return fmt.Errorf("cannot collect trust center access: %w", err) } diff --git a/pkg/probo/trust_center_access_service.go b/pkg/probo/trust_center_access_service.go index 632ed0062..47538dea6 100644 --- a/pkg/probo/trust_center_access_service.go +++ b/pkg/probo/trust_center_access_service.go @@ -27,7 +27,6 @@ import ( "github.com/getprobo/probo/pkg/page" "github.com/getprobo/probo/pkg/statelesstoken" "github.com/getprobo/probo/pkg/usrmgr" - "github.com/jackc/pgx/v5" "go.gearno.de/kit/pg" ) @@ -142,10 +141,11 @@ func (s TrustCenterAccessService) Create( if err := existingAccess.Delete(ctx, tx, s.svc.scope); err != nil { return fmt.Errorf("cannot delete existing trust center access: %w", err) } - } - - if err != nil && !errors.Is(err, pgx.ErrNoRows) { - return fmt.Errorf("cannot load trust center access: %w", err) + } else { + var notFoundErr *coredata.ErrTrustCenterAccessNotFound + if !errors.As(err, ¬FoundErr) { + return fmt.Errorf("cannot load trust center access: %w", err) + } } access = &coredata.TrustCenterAccess{ diff --git a/pkg/trust/trust_center_access_service.go b/pkg/trust/trust_center_access_service.go index 51a2e7954..acfadf947 100644 --- a/pkg/trust/trust_center_access_service.go +++ b/pkg/trust/trust_center_access_service.go @@ -26,7 +26,6 @@ import ( "github.com/getprobo/probo/pkg/probo" "github.com/getprobo/probo/pkg/statelesstoken" "github.com/getprobo/probo/pkg/usrmgr" - "github.com/jackc/pgx/v5" "go.gearno.de/kit/pg" ) @@ -108,10 +107,11 @@ func (s TrustCenterAccessService) Create( if err := existingAccess.Delete(ctx, tx, s.svc.scope); err != nil { return fmt.Errorf("cannot delete existing trust center access: %w", err) } - } - - if err != nil && !errors.Is(err, pgx.ErrNoRows) { - return fmt.Errorf("cannot load trust center access: %w", err) + } else { + var notFoundErr *coredata.ErrTrustCenterAccessNotFound + if !errors.As(err, ¬FoundErr) { + return fmt.Errorf("cannot load trust center access: %w", err) + } } access = &coredata.TrustCenterAccess{