Repository: absmach/supermq (go)

Issue:
Bug: Issue token return missing identity
### What were you trying to achieve?

Trying to issue token without username / email

### What are the expected results?

{
    "error": "missing username / email",
    "message": "something went wrong with the request"
}


### What are the received results?

{
    "error": "missing entity identity",
    "message": "something went wrong with the request"
}

### Steps To Reproduce

Sent request following request 
```bash
curl --location --request POST 'http://localhost/users/tokens/issue' \
--header 'Content-Type: application/json
```

### In what environment did you encounter the issue?

Docker

### Additional information you deem important

_No response_

Pull request description:
SMQ-3001 - Fix issue token return error
<!-- Copyright (c) Abstract Machines
SPDX-License-Identifier: Apache-2.0 -->

<!--

Pull request title should be `SMQ-XXX - description` or `NOISSUE - description` where XXX is ID of the issue that this PR relate to.
Please review the [CONTRIBUTING.md](https://github.com/absmach/supermq/blob/main/CONTRIBUTING.md) file for detailed contributing guidelines.

For Work In Progress Pull Requests, please use the Draft PR feature, see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for further details.

For a timely review/response, please avoid force-pushing additional commits if your PR already received reviews or comments.

- Provide tests for your changes.
- Use descriptive commit messages.
- Comment your code where appropriate.
- Squash your commits
- Update any related documentation.
-->

# What type of PR is this?

<!--This represents the type of PR you are submitting.

For example:
This is a bug fix because it fixes the following issue: #1234
This is a feature because it adds the following functionality: ...
This is a refactor because it changes the following functionality: ...
This is a documentation update because it updates the following documentation: ...
This is a dependency update because it updates the following dependencies: ...
This is an optimization because it improves the following functionality: ...
-->

## What does this do?

<!--
Please provide a brief description of what this PR is intended to do.
Include List any changes that modify/break current functionality.
-->

## Which issue(s) does this PR fix/relate to?

<!--
For pull requests that relate or close an issue, please include them below.  We like to follow [Github's guidance on linking issues to pull requests](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue).

For example having the text: "Resolves #1234" would connect the current pull request to issue 1234.  And when we merge the pull request, Github will automatically close the issue.
-->

- Related Issue #3001 
- Resolves #3001 

## Have you included tests for your changes?
Yes, I have tested manually
<!--If you have not included tests, please explain why.
For example:
Yes, I have included tests for my changes.
No, I have not included tests because I do not know how to.
-->

## Did you document any new/modified feature?

<!--If you have not included documentation, please explain why.
For example:
Yes, I have updated the documentation for the new feature.
No, I have not updated the documentation because I do not know how to.
-->

### Notes

<!--Please provide any additional information you feel is important.-->


Patch:
diff --git a/api/http/common.go b/api/http/common.go
index eacbe01d2..e7eda197a 100644
--- a/api/http/common.go
+++ b/api/http/common.go
@@ -231,6 +231,7 @@ func EncodeError(_ context.Context, err error, w http.ResponseWriter) {
 		errors.Contains(err, apiutil.ErrMissingUserID),
 		errors.Contains(err, apiutil.ErrMissingPATID),
 		errors.Contains(err, apiutil.ErrMissingUsername),
+		errors.Contains(err, apiutil.ErrMissingUsernameEmail),
 		errors.Contains(err, apiutil.ErrMissingFirstName),
 		errors.Contains(err, apiutil.ErrMissingLastName),
 		errors.Contains(err, apiutil.ErrInvalidUsername),
diff --git a/api/http/util/errors.go b/api/http/util/errors.go
index 90817cbdc..c7554fccf 100644
--- a/api/http/util/errors.go
+++ b/api/http/util/errors.go
@@ -265,4 +265,7 @@ var (
 
 	// ErrInvalidRouteFormat indicates invalid route format.
 	ErrInvalidRouteFormat = errors.New("invalid route format")
+
+	// ErrMissingUsernameEmail indicates missing user name / email.
+	ErrMissingUsernameEmail = errors.New("missing username / email")
 )
diff --git a/users/api/requests.go b/users/api/requests.go
index c11e3088f..e954ef76e 100644
--- a/users/api/requests.go
+++ b/users/api/requests.go
@@ -253,7 +253,7 @@ type loginUserReq struct {
 
 func (req loginUserReq) validate() error {
 	if req.Username == "" {
-		return apiutil.ErrMissingIdentity
+		return apiutil.ErrMissingUsernameEmail
 	}
 	if req.Password == "" {
 		return apiutil.ErrMissingPass


Test patch:
diff --git a/pkg/sdk/tokens_test.go b/pkg/sdk/tokens_test.go
index 93eecc885..793d190e1 100644
--- a/pkg/sdk/tokens_test.go
+++ b/pkg/sdk/tokens_test.go
@@ -85,7 +85,7 @@ func TestIssueToken(t *testing.T) {
 			svcRes:   &grpcTokenV1.Token{},
 			svcErr:   nil,
 			response: sdk.Token{},
-			err:      errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, apiutil.ErrMissingIdentity), http.StatusBadRequest),
+			err:      errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, apiutil.ErrMissingUsernameEmail), http.StatusBadRequest),
 		},
 		{
 			desc: "issue token with empty secret",
diff --git a/users/api/requests_test.go b/users/api/requests_test.go
index 477836177..ac2cd5a5e 100644
--- a/users/api/requests_test.go
+++ b/users/api/requests_test.go
@@ -533,7 +533,7 @@ func TestLoginUserReqValidate(t *testing.T) {
 				Username: "",
 				Password: secret,
 			},
-			err: apiutil.ErrMissingIdentity,
+			err: apiutil.ErrMissingUsernameEmail,
 		},
 		{
 			desc: "empty secret",