Improve framework import error handling

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-04-09 22:21:34 -07:00
parent 1f1c133a9d
commit 41861f2c9f
2 changed files with 16 additions and 0 deletions

View File

@@ -9,6 +9,10 @@ All notable changes to this project will be documented in this file.
- Simplified policy data model by removing version field and optimistic concurrency - Simplified policy data model by removing version field and optimistic concurrency
- Refactored policy update flow to load-modify-save pattern - Refactored policy update flow to load-modify-save pattern
### Fixed
- Added user-friendly error messages when importing frameworks that already exist
## [0.4.1] - 2025-04-09 ## [0.4.1] - 2025-04-09
### Changed ### Changed

View File

@@ -7,6 +7,7 @@ package console_v1
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"time" "time"
@@ -459,6 +460,17 @@ func (r *mutationResolver) ImportFramework(ctx context.Context, input types.Impo
framework, err := svc.Frameworks.Import(ctx, input.OrganizationID, req) framework, err := svc.Frameworks.Import(ctx, input.OrganizationID, req)
if err != nil { if err != nil {
var errFrameworkReferenceIDAlreadyExists *coredata.ErrFrameworkReferenceIDAlreadyExists
if errors.As(err, &errFrameworkReferenceIDAlreadyExists) {
return nil, &gqlerror.Error{
Err: err,
Message: fmt.Sprintf("framework %q already exists", req.Framework.Name),
Extensions: map[string]any{
"frameworkReferenceId": errFrameworkReferenceIDAlreadyExists.ReferenceID,
},
}
}
return nil, fmt.Errorf("cannot import framework: %w", err) return nil, fmt.Errorf("cannot import framework: %w", err)
} }