Skip to content

Commit

Permalink
Added rollback error
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
  • Loading branch information
nyagamunene committed Jun 12, 2024
1 parent 363c11d commit 7aacba8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 0 additions & 2 deletions pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package errors

import (
"encoding/json"
"errors"
)

// Error specifies an API that must be fullfiled by error type.
Expand Down Expand Up @@ -86,7 +85,6 @@ func Contains(e1, e2 error) bool {
return e1.Error() == e2.Error()
}


// Wrap returns an Error that wrap err with wrapper.
func Wrap(wrapper, err error) Error {
if wrapper == nil || err == nil {
Expand Down
14 changes: 14 additions & 0 deletions pkg/errors/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,17 @@ func (sae *StatusAlreadyAssignedError) Error() string {
var ErrStatusAlreadyAssigned = &StatusAlreadyAssignedError{
Err: New("status already assigned"),
}

// ErrRollbackTx indicates failed to rollback transaction.

type RollbackTxError struct {
Err Error
}

func (rte *RollbackTxError) Error() string {
return rte.Err.Error()
}

var ErrRollbackTx = &RollbackTxError{
Err: New("failed to rollback transaction"),
}
4 changes: 2 additions & 2 deletions things/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ func (svc *service) authorize(ctx context.Context, domainID, subjType, subjKind,
return res.GetId(), nil
}

func (svc service) addThingPolicies(ctx context.Context, userID, domainID string, things []mgclients.Client) error {
func (svc service) addThingPolicies(ctx context.Context, userID, domainID string, things []mgclients.Client) errors.Error {
policies := magistrala.AddPoliciesReq{}
for _, thing := range things {
policies.AddPoliciesReq = append(policies.AddPoliciesReq, &magistrala.AddPolicyReq{
Expand Down Expand Up @@ -626,7 +626,7 @@ func (svc service) addThingPolicies(ctx context.Context, userID, domainID string
return nil
}

func (svc service) addThingPoliciesRollback(ctx context.Context, userID, domainID string, things []mgclients.Client) error {
func (svc service) addThingPoliciesRollback(ctx context.Context, userID, domainID string, things []mgclients.Client) errors.Error {
policies := magistrala.DeletePoliciesReq{}
for _, thing := range things {
policies.DeletePoliciesReq = append(policies.DeletePoliciesReq, &magistrala.DeletePolicyReq{
Expand Down

0 comments on commit 7aacba8

Please sign in to comment.