diff --git a/auth/domains.go b/auth/domains.go index afc7448abbf..c39dd46c8f4 100644 --- a/auth/domains.go +++ b/auth/domains.go @@ -10,8 +10,8 @@ import ( "strings" "time" - "github.com/absmach/magistrala/internal/apiutil" "github.com/absmach/magistrala/pkg/clients" + svcerr "github.com/absmach/magistrala/pkg/errors/service" ) // Status represents Domain status. @@ -73,7 +73,7 @@ func ToStatus(status string) (Status, error) { case All: return AllStatus, nil } - return Status(0), apiutil.ErrInvalidStatus + return Status(0), svcerr.ErrInvalidStatus } // Custom Marshaller for Domains status. diff --git a/auth/domains_test.go b/auth/domains_test.go index f24a18ff6e9..82875bccd58 100644 --- a/auth/domains_test.go +++ b/auth/domains_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/absmach/magistrala/auth" - "github.com/absmach/magistrala/internal/apiutil" + svcerr "github.com/absmach/magistrala/pkg/errors/service" "github.com/stretchr/testify/assert" ) @@ -87,7 +87,7 @@ func TestToStatus(t *testing.T) { desc: "Unknown", status: "unknown", expetcted: auth.Status(0), - err: apiutil.ErrInvalidStatus, + err: svcerr.ErrInvalidStatus, }, } @@ -171,7 +171,7 @@ func TestStatusUnmarshalJSON(t *testing.T) { desc: "Unknown", expected: auth.Status(0), status: []byte(`"unknown"`), - err: apiutil.ErrInvalidStatus, + err: svcerr.ErrInvalidStatus, }, } diff --git a/internal/api/common.go b/internal/api/common.go index bda9981ed1f..bad612c4be5 100644 --- a/internal/api/common.go +++ b/internal/api/common.go @@ -115,7 +115,6 @@ func EncodeError(_ context.Context, err error, w http.ResponseWriter) { errors.Contains(err, apiutil.ErrBearerKey), errors.Contains(err, apiutil.ErrNameSize), errors.Contains(err, apiutil.ErrInvalidIDFormat), - errors.Contains(err, apiutil.ErrInvalidStatus), errors.Contains(err, svcerr.ErrInvalidStatus), errors.Contains(err, apiutil.ErrValidation), errors.Contains(err, apiutil.ErrInvitationState), diff --git a/internal/apiutil/errors.go b/internal/apiutil/errors.go index dabe5881d2f..ed5c2cd77e2 100644 --- a/internal/apiutil/errors.go +++ b/internal/apiutil/errors.go @@ -33,9 +33,6 @@ var ( // ErrEmailSize indicates that email size exceeds the max. ErrEmailSize = errors.New("invalid email size") - // ErrInvalidStatus indicates an invalid user account status. - ErrInvalidStatus = errors.New("invalid user account status") - // ErrInvalidRole indicates that an invalid role. ErrInvalidRole = errors.New("invalid client role") diff --git a/internal/groups/service.go b/internal/groups/service.go index 17acc0d2e59..78a6f621aa2 100644 --- a/internal/groups/service.go +++ b/internal/groups/service.go @@ -54,7 +54,7 @@ func (svc service) CreateGroup(ctx context.Context, token, kind string, g groups return groups.Group{}, err } if g.Status != mgclients.EnabledStatus && g.Status != mgclients.DisabledStatus { - return groups.Group{}, apiutil.ErrInvalidStatus + return groups.Group{}, svcerr.ErrInvalidStatus } g.ID = groupID diff --git a/internal/groups/service_test.go b/internal/groups/service_test.go index 27748e62fd7..2d513f04db3 100644 --- a/internal/groups/service_test.go +++ b/internal/groups/service_test.go @@ -155,7 +155,7 @@ func TestCreateGroup(t *testing.T) { authzResp: &magistrala.AuthorizeRes{ Authorized: true, }, - err: apiutil.ErrInvalidStatus, + err: svcerr.ErrInvalidStatus, }, { desc: "successfully with parent", diff --git a/internal/groups/status.go b/internal/groups/status.go index 85807e959ce..d967dbc0b44 100644 --- a/internal/groups/status.go +++ b/internal/groups/status.go @@ -3,7 +3,7 @@ package groups -import "github.com/absmach/magistrala/internal/apiutil" +import svcerr "github.com/absmach/magistrala/pkg/errors/service" // Status represents Group status. type Status uint8 @@ -54,5 +54,5 @@ func ToStatus(status string) (Status, error) { case All: return AllStatus, nil } - return Status(0), apiutil.ErrInvalidStatus + return Status(0), svcerr.ErrInvalidStatus } diff --git a/internal/groups/status_test.go b/internal/groups/status_test.go index e0525381201..a715ee392d8 100644 --- a/internal/groups/status_test.go +++ b/internal/groups/status_test.go @@ -6,8 +6,8 @@ package groups_test import ( "testing" - "github.com/absmach/magistrala/internal/apiutil" "github.com/absmach/magistrala/internal/groups" + svcerr "github.com/absmach/magistrala/pkg/errors/service" "github.com/stretchr/testify/assert" ) @@ -39,7 +39,7 @@ func TestToStatus(t *testing.T) { {"Enabled", "enabled", groups.EnabledStatus, nil}, {"Disabled", "disabled", groups.DisabledStatus, nil}, {"All", "all", groups.AllStatus, nil}, - {"Unknown", "unknown", groups.Status(0), apiutil.ErrInvalidStatus}, + {"Unknown", "unknown", groups.Status(0), svcerr.ErrInvalidStatus}, } for _, tc := range cases { diff --git a/pkg/clients/status.go b/pkg/clients/status.go index 82a716d5113..7d9ffcb9709 100644 --- a/pkg/clients/status.go +++ b/pkg/clients/status.go @@ -7,7 +7,7 @@ import ( "encoding/json" "strings" - "github.com/absmach/magistrala/internal/apiutil" + svcerr "github.com/absmach/magistrala/pkg/errors/service" ) // Status represents Client status. @@ -59,7 +59,7 @@ func ToStatus(status string) (Status, error) { case All: return AllStatus, nil } - return Status(0), apiutil.ErrInvalidStatus + return Status(0), svcerr.ErrInvalidStatus } // Custom Marshaller for Client/Groups. diff --git a/pkg/clients/status_test.go b/pkg/clients/status_test.go index 1d6e08f1981..3e9540a1f52 100644 --- a/pkg/clients/status_test.go +++ b/pkg/clients/status_test.go @@ -6,8 +6,8 @@ package clients_test import ( "testing" - "github.com/absmach/magistrala/internal/apiutil" "github.com/absmach/magistrala/pkg/clients" + svcerr "github.com/absmach/magistrala/pkg/errors/service" "github.com/stretchr/testify/assert" ) @@ -76,7 +76,7 @@ func TestToStatus(t *testing.T) { desc: "Unknown", status: "unknown", expetcted: clients.Status(0), - err: apiutil.ErrInvalidStatus, + err: svcerr.ErrInvalidStatus, }, } @@ -160,7 +160,7 @@ func TestStatusUnmarshalJSON(t *testing.T) { desc: "Unknown", expected: clients.Status(0), status: []byte(`"unknown"`), - err: apiutil.ErrInvalidStatus, + err: svcerr.ErrInvalidStatus, }, }