Skip to content

Commit

Permalink
add unauthorizated error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ludaciti committed Sep 27, 2021
1 parent f100530 commit 56843d6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions costradar/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/tidwall/gjson"
"io/ioutil"
"net/http"
"strconv"
)

type AccessConfig struct {
Expand Down Expand Up @@ -95,6 +96,11 @@ func (c *ClientGraphql) graphql(query string, variables map[string]interface{},
body, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()

if resp.StatusCode != 200 {
err = errors.New("Status code: " + strconv.Itoa(resp.StatusCode) + ". Message: " + gjson.GetBytes(body, "error").String())
return nil, err
}

errorMessage := getErrorFromBody(body, dataPath)

if errorMessage != "" {
Expand Down
10 changes: 5 additions & 5 deletions costradar/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
// Warning or errors can be collected in a slice type
var diags diag.Diagnostics

diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "Warning Message Summary",
Detail: "This is the detailed warning message from providerConfigure",
})
//diags = append(diags, diag.Diagnostic{
// Severity: diag.Warning,
// Summary: "Warning Message Summary",
// Detail: "This is the detailed warning message from providerConfigure",
//})

return NewCostRadarClient(endpoint, token), diags
}
File renamed without changes.
File renamed without changes.

0 comments on commit 56843d6

Please sign in to comment.