Skip to content

Commit

Permalink
Return an error from whoami for unauthenticate users (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbialon authored Jan 27, 2023
1 parent f1671a6 commit d0387e8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/cmd/whoami/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"

"github.com/pkg/errors"
"github.com/urfave/cli/v2"

"github.com/spacelift-io/spacectl/client/session"
Expand All @@ -28,13 +29,16 @@ func Command() *cli.Command {
}

var query struct {
Viewer struct {
Viewer *struct {
ID string `graphql:"id" json:"id"`
Name string `graphql:"name" json:"name"`
}
}
if err := authenticated.Client.Query(cliCtx.Context, &query, map[string]interface{}{}); err != nil {
return err
return errors.Wrap(err, "failed to query user information")
}
if query.Viewer == nil {
return errors.New("failed to query user information: unauthorized")
}

encoder := json.NewEncoder(os.Stdout)
Expand Down

0 comments on commit d0387e8

Please sign in to comment.