Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions generated/stackstate_api/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3541,6 +3541,12 @@ paths:
schema:
$ref: '#/components/schemas/ServerInfo'
description: Server information
"401":
content:
application/json:
schema:
$ref: '#/components/schemas/GenericErrorsResponse'
description: Error when handling the request on the server side.
"500":
content:
application/json:
Expand Down
10 changes: 10 additions & 0 deletions generated/stackstate_api/api_server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 24 additions & 2 deletions internal/common/common_cli_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"strings"

"github.com/stackvista/stackstate-cli/generated/stackstate_api"
"github.com/stackvista/stackstate-cli/internal/util"
)

Expand Down Expand Up @@ -39,9 +40,30 @@ func NewConnectError(err error, apiURL string, serverResponse *http.Response) CL
}

if statusCode == HTTPStatusUnauthorized {
var errMessage string

if apiErr, ok := err.(*stackstate_api.GenericOpenAPIError); ok {
if detailedErr, ok := apiErr.Model().(stackstate_api.GenericErrorsResponse); ok {
// Now you can access your 401 error details
var messages []string
for _, apiErr := range detailedErr.Errors {
messages = append(messages, apiErr.Message)
}
errMessage = strings.Join(messages, ", ")
// Some responses do not yield more than the 401, others give in the body the error message as the RefreshToken failed or so
if errMessage == "" {
errMessage = "invalid api-token"
}
} else {
errMessage = err.Error()
}
} else {
errMessage = err.Error()
}

return StdCLIError{
Err: fmt.Errorf("could not connect to %s: invalid api-token\n"+
"For more information: https://l.stackstate.com/cli-invalid-api-token", apiURL),
Err: fmt.Errorf("could not connect to %s: %s\n"+
"For more information: https://l.stackstate.com/cli-invalid-api-token", apiURL, errMessage),
exitCode: ConnectErrorExitCode,
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion stackstate_openapi/openapi_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3e7ca840dfb06920cbffa0b7f70130d6b17e0721
eb3e3df341ccfd167ed8c2e2c14b63a38be686b3
Loading