Replace panic calls with proper error handling in resolvers

All panic(fmt.Errorf(...)) calls in the console and trust center
GraphQL resolvers are replaced with structured error logging via
r.logger.ErrorCtx and gqlutils.Internal(ctx) returns.

Mutation resolvers for Create, Update, Upload, Import, and Assess
operations now check for validator.ValidationErrors before returning
an internal error, surfacing field-level INVALID errors to clients
via gqlutils.InvalidValidationErrors.

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2026-03-17 14:51:24 +01:00
parent 16b966b8fb
commit 73d5dbb5db
2 changed files with 885 additions and 540 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -956,12 +956,14 @@ func (r *queryResolver) CurrentTrustCenter(ctx context.Context) (*types.TrustCen
org, err := trustService.Organizations.Get(ctx, trustCenter.OrganizationID)
if err != nil {
panic(fmt.Errorf("cannot get organization: %w", err))
r.logger.ErrorCtx(ctx, "cannot get organization", log.Error(err))
return nil, gqlutils.Internal(ctx)
}
trustCenter, err = trustService.TrustCenters.Get(ctx, trustCenter.ID)
if err != nil {
panic(fmt.Errorf("cannot get trust center: %w", err))
r.logger.ErrorCtx(ctx, "cannot get trust center", log.Error(err))
return nil, gqlutils.Internal(ctx)
}
response := types.NewTrustCenter(trustCenter)
@@ -1368,7 +1370,8 @@ func (r *trustCenterReferenceResolver) LogoURL(ctx context.Context, obj *types.T
logoURL, err := trustService.TrustCenterReferences.GenerateLogoURL(ctx, obj.ID, 1*time.Hour)
if err != nil {
panic(fmt.Errorf("cannot generate logo URL: %w", err))
r.logger.ErrorCtx(ctx, "cannot generate logo URL", log.Error(err))
return "", gqlutils.Internal(ctx)
}
return logoURL, nil
@@ -1382,12 +1385,14 @@ func (r *vendorConnectionResolver) TotalCount(ctx context.Context, obj *types.Ve
case *trustCenterResolver:
count, err := trustService.Vendors.CountForTrustCenterId(ctx, obj.ParentID)
if err != nil {
panic(fmt.Errorf("cannot count vendors: %w", err))
r.logger.ErrorCtx(ctx, "cannot count vendors", log.Error(err))
return 0, gqlutils.Internal(ctx)
}
return count, nil
}
panic(fmt.Errorf("not implemented: TotalCount for parent type %T", obj.Resolver))
r.logger.ErrorCtx(ctx, "not implemented: TotalCount for parent type")
return 0, gqlutils.Internal(ctx)
}
// Audit returns schema.AuditResolver implementation.