Skip to content

Commit

Permalink
SCALRCORE-18723 Fix Provider to handle 404 error
Browse files Browse the repository at this point in the history
  • Loading branch information
ablik committed Aug 31, 2021
1 parent 2102a58 commit 89c9dd2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scalr.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func checkResponseCode(r *http.Response) error {
err := json.NewDecoder(r.Body).Decode(errPayload)
if err != nil || len(errPayload.Errors) == 0 {
if r.StatusCode == 404 {
return &ErrResourceNotFound{}
return ErrResourceNotFound{}
} else {
return fmt.Errorf(r.Status)
}
Expand Down
16 changes: 16 additions & 0 deletions scalr_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package scalr

import (
"bytes"
"context"
"errors"
"github.com/stretchr/testify/assert"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -245,6 +248,19 @@ func TestClient_retryHTTPCheck(t *testing.T) {
}
}

func TestClient_notFoundErrorWithoutMessage(t *testing.T) {
resp := &http.Response{
StatusCode: 404,
Body: ioutil.NopCloser(bytes.NewBufferString("test boody")),
}
err := checkResponseCode(resp)

if err != nil {
assert.Error(t, err)
assert.Equal(t, err, ErrResourceNotFound{})
}
}

func setupEnvVars(token, address string) func() {
origToken := os.Getenv("SCALR_TOKEN")
origAddress := os.Getenv("SCALR_ADDRESS")
Expand Down

0 comments on commit 89c9dd2

Please sign in to comment.