Add error when unauthorized
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/99designs/gqlgen/graphql"
|
||||||
"github.com/vektah/gqlparser/v2/gqlerror"
|
"github.com/vektah/gqlparser/v2/gqlerror"
|
||||||
"go.gearno.de/kit/log"
|
"go.gearno.de/kit/log"
|
||||||
"go.probo.inc/probo/pkg/coredata"
|
"go.probo.inc/probo/pkg/coredata"
|
||||||
@@ -146,8 +147,26 @@ func (r *identityResolver) Permission(ctx context.Context, obj *types.Identity,
|
|||||||
Action: action,
|
Action: action,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
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
|
return true, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user