Create access not found error

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-08-22 11:17:49 +02:00
parent d31f611e63
commit 3401271a3f
3 changed files with 27 additions and 10 deletions

View File

@@ -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)
}

View File

@@ -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, &notFoundErr) {
return fmt.Errorf("cannot load trust center access: %w", err)
}
}
access = &coredata.TrustCenterAccess{

View File

@@ -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, &notFoundErr) {
return fmt.Errorf("cannot load trust center access: %w", err)
}
}
access = &coredata.TrustCenterAccess{