Skip to content

Commit

Permalink
fix(notifiers): wrap with create entity error
Browse files Browse the repository at this point in the history
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
  • Loading branch information
rodneyosodo committed Jun 18, 2024
1 parent df99962 commit 7a9516f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions api/openapi/notifiers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ paths:
$ref: "#/components/responses/Create"
"400":
description: Failed due to malformed JSON.
"401":
description: Missing or invalid access token provided.
"403":
description: Failed to perform authorization over the entity.
"409":
Expand Down
7 changes: 6 additions & 1 deletion consumers/notifiers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/absmach/magistrala"
"github.com/absmach/magistrala/consumers"
"github.com/absmach/magistrala/pkg/errors"
svcerr "github.com/absmach/magistrala/pkg/errors/service"
"github.com/absmach/magistrala/pkg/messaging"
)

Expand Down Expand Up @@ -72,7 +73,11 @@ func (ns *notifierService) CreateSubscription(ctx context.Context, token string,
}

sub.OwnerID = res.GetId()
return ns.subs.Save(ctx, sub)
id, err := ns.subs.Save(ctx, sub)
if err != nil {
return "", errors.Wrap(svcerr.ErrCreateEntity, err)
}
return id, nil
}

func (ns *notifierService) ViewSubscription(ctx context.Context, token, id string) (Subscription, error) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/auth/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"github.com/absmach/magistrala"
authgrpcapi "github.com/absmach/magistrala/auth/api/grpc"
"github.com/absmach/magistrala/auth/mocks"
"github.com/absmach/magistrala/internal/server"
grpcserver "github.com/absmach/magistrala/internal/server/grpc"
mglog "github.com/absmach/magistrala/logger"
"github.com/absmach/magistrala/pkg/auth"
"github.com/absmach/magistrala/pkg/errors"
"github.com/absmach/magistrala/pkg/server"
grpcserver "github.com/absmach/magistrala/pkg/server/grpc"
thingsgrpcapi "github.com/absmach/magistrala/things/api/grpc"
thmocks "github.com/absmach/magistrala/things/mocks"
"github.com/stretchr/testify/assert"
Expand All @@ -29,7 +29,7 @@ func TestSetupAuth(t *testing.T) {
registerAuthServiceServer := func(srv *grpc.Server) {
magistrala.RegisterAuthServiceServer(srv, authgrpcapi.NewServer(new(mocks.Service)))
}
gs := grpcserver.New(ctx, cancel, "auth", server.Config{Port: "12345"}, registerAuthServiceServer, mglog.NewMock())
gs := grpcserver.NewServer(ctx, cancel, "auth", server.Config{Port: "12345"}, registerAuthServiceServer, mglog.NewMock())
go func() {
err := gs.Start()
assert.Nil(t, err, fmt.Sprintf(`"Unexpected error creating server %s"`, err))
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestSetupAuthz(t *testing.T) {
registerAuthaServiceServer := func(srv *grpc.Server) {
magistrala.RegisterAuthzServiceServer(srv, thingsgrpcapi.NewServer(new(thmocks.Service)))
}
gs := grpcserver.New(ctx, cancel, "things", server.Config{Port: "12345"}, registerAuthaServiceServer, mglog.NewMock())
gs := grpcserver.NewServer(ctx, cancel, "things", server.Config{Port: "12345"}, registerAuthaServiceServer, mglog.NewMock())
go func() {
err := gs.Start()
assert.Nil(t, err, fmt.Sprintf(`"Unexpected error creating server %s"`, err))
Expand Down
2 changes: 1 addition & 1 deletion pkg/sdk/go/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/http"
"time"

"github.com/absmach/magistrala/internal/apiutil"
"github.com/absmach/magistrala/pkg/apiutil"
"github.com/absmach/magistrala/pkg/errors"
)

Expand Down

0 comments on commit 7a9516f

Please sign in to comment.