Skip to content

Commit

Permalink
updates as per PR review
Browse files Browse the repository at this point in the history
Signed-off-by: robertojrojas <[email protected]>
  • Loading branch information
robertojrojas committed Aug 7, 2023
1 parent 9673899 commit 74e196e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
17 changes: 6 additions & 11 deletions internal/errorcodes/errorcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,16 @@ func FeatureEnabled(md map[string]string) bool {

// NewStatusError returns a Status representing Code, error Reason, Message, and optional ResourceInfo and Metadata.
// When successful, it returns a StatusError, otherwise returns the original error
func NewStatusError(code codes.Code, err error, errDescription string, reason Reason, rid *ResourceInfoData, metadata map[string]string) error {
md := metadata
if md == nil {
md = map[string]string{}
}

func NewStatusError(code codes.Code, err error, reason Reason, rid *ResourceInfoData, metadata map[string]string) error {
messages := []protoiface.MessageV1{
NewErrorInfo(reason, md),
NewErrorInfo(reason, metadata),
}

if rid != nil {
messages = append(messages, NewResourceInfo(rid, errDescription))
messages = append(messages, NewResourceInfo(rid, err))
}

ste, stErr := status.New(code, errDescription).WithDetails(messages...)
ste, stErr := status.New(code, err.Error()).WithDetails(messages...)
if stErr != nil {
return err
}
Expand All @@ -77,11 +72,11 @@ func NewErrorInfo(reason Reason, md map[string]string) *errdetails.ErrorInfo {
return &ei
}

func NewResourceInfo(rid *ResourceInfoData, description string) *errdetails.ResourceInfo {
func NewResourceInfo(rid *ResourceInfoData, err error) *errdetails.ResourceInfo {
return &errdetails.ResourceInfo{
ResourceType: rid.ResourceType,
ResourceName: rid.ResourceName,
Owner: Owner,
Description: description,
Description: err.Error(),
}
}
8 changes: 4 additions & 4 deletions state/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ func (r *StateStore) Delete(ctx context.Context, req *state.DeleteRequest) error
}
if err != nil {
if errorcodes.FeatureEnabled(req.Metadata) {
errMsg := fmt.Sprintf("state store Delete - possible etag(%s) %s. original error: %v", *req.ETag, string(state.ETagMismatch), err)
return errorcodes.NewStatusError(codes.InvalidArgument, err, errMsg, errorcodes.StateETagMismatchReason, &r.resourceInfoData, nil)
ew := fmt.Errorf("state store Delete - possible etag(%s) %s. original error: %v", *req.ETag, string(state.ETagMismatch), err)
return errorcodes.NewStatusError(codes.InvalidArgument, ew, errorcodes.StateETagMismatchReason, &r.resourceInfoData, nil)
}

return state.NewETagError(state.ETagMismatch, err)
Expand Down Expand Up @@ -367,8 +367,8 @@ func (r *StateStore) Set(ctx context.Context, req *state.SetRequest) error {
if err != nil {
if req.HasETag() {
if errorcodes.FeatureEnabled(req.Metadata) {
errMsg := fmt.Sprintf("state store Set - possible etag(%s) %s. original error: %v", *req.ETag, string(state.ETagMismatch), err)
return errorcodes.NewStatusError(codes.InvalidArgument, fmt.Errorf(errMsg), errMsg, errorcodes.StateETagMismatchReason, &r.resourceInfoData, nil)
ew := fmt.Errorf("state store Set - possible etag(%s) %s. original error: %v", *req.ETag, string(state.ETagMismatch), err)
return errorcodes.NewStatusError(codes.InvalidArgument, ew, errorcodes.StateETagMismatchReason, &r.resourceInfoData, nil)
}

return state.NewETagError(state.ETagMismatch, err)
Expand Down

0 comments on commit 74e196e

Please sign in to comment.