Skip to content

Commit 05fb952

Browse files
Philip Reichenbergerpaperspace-philip
authored andcommitted
fix response success status
1 parent 88b4cd3 commit 05fb952

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

api_backend.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
)
1616

1717
var DefaultBaseURL = "https://api.paperspace.io"
18+
var SuccessStatusCodes = []int{200, 201, 202, 203, 204}
1819

1920
type APIBackend struct {
2021
BaseURL string
@@ -42,13 +43,12 @@ func NewAPIBackend() *APIBackend {
4243
if debug != "" {
4344
apiBackend.Debug = true
4445
}
45-
46+
4647
debugBody := os.Getenv("PAPERSPACE_DEBUG_BODY")
4748
if debugBody != "" {
4849
apiBackend.DebugBody = true
4950
}
5051

51-
5252
return &apiBackend
5353
}
5454

@@ -125,7 +125,15 @@ func (c *APIBackend) request(method string, url string,
125125
c.debug(string(responseDump))
126126
}
127127

128-
if res.StatusCode != 200 {
128+
isSuccessResponse := false
129+
for _, statusCode := range SuccessStatusCodes {
130+
if res.StatusCode == statusCode {
131+
isSuccessResponse = true
132+
break
133+
}
134+
}
135+
136+
if !isSuccessResponse {
129137
defer res.Body.Close()
130138
errorBody, err := ioutil.ReadAll(res.Body)
131139
if err != nil {

0 commit comments

Comments
 (0)