feat: [CODE-2318]: Update error message in case of forbidden (#2780)

* feat: [CODE-2318]: update error logic to be translate in controller
* Merge branch 'main' into akp/CODE-2318
* feat: [CODE-2318]: update error logic to be translate in controller
* feat: [CODE-2318]: remove nested error handling
* feat: [CODE-2318]: Update error message in case of forbidden
pull/3576/head
Akhilesh Pandey 2024-10-18 14:16:16 +00:00 committed by Harness
parent d21176e612
commit fd848b1e15
1 changed files with 10 additions and 2 deletions

View File

@ -16,6 +16,7 @@ package principal
import (
"context"
"errors"
"net/http"
apiauth "github.com/harness/gitness/app/api/auth"
@ -41,7 +42,7 @@ func (c controller) List(
)
}
if err := apiauth.Check(
err := apiauth.Check(
ctx,
c.authorizer,
session,
@ -50,7 +51,14 @@ func (c controller) List(
Type: enum.ResourceTypeUser,
},
enum.PermissionUserView,
); err != nil {
)
if errors.Is(err, apiauth.ErrNotAuthorized) {
return nil, usererror.Forbidden(
"You lack the permission to list users. " +
"Please grant User view permission at the account level.",
)
}
if err != nil {
return nil, err
}