Add error when unauthorized

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2025-12-24 10:38:24 +01:00
parent 5ae8da7610
commit 600d763d18

View File

@@ -11,6 +11,7 @@ import (
"fmt"
"time"
"github.com/99designs/gqlgen/graphql"
"github.com/vektah/gqlparser/v2/gqlerror"
"go.gearno.de/kit/log"
"go.probo.inc/probo/pkg/coredata"
@@ -146,8 +147,26 @@ func (r *identityResolver) Permission(ctx context.Context, obj *types.Identity,
Action: action,
},
)
if err != nil {
return false, nil
var errInsufficientPermissions *iam.ErrInsufficientPermissions
if errors.As(err, &errInsufficientPermissions) {
graphql.AddError(
ctx,
&gqlerror.Error{
Path: graphql.GetPath(ctx),
Message: err.Error(),
Extensions: map[string]interface{}{
"code": "UNAUTHORIZED",
},
},
)
return false, nil
}
r.logger.ErrorCtx(ctx, "cannot authorize", log.Error(err))
return false, gqlutils.InternalServerError(ctx)
}
return true, nil