Skip to content

Commit a8ab741

Browse files
committed
fix(client): show non-JSON HTTP errors
1 parent 9972c74 commit a8ab741

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

client/controller/client/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func checkForErrors(res *http.Response, body string) error {
111111
bodyMap := make(map[string]interface{})
112112

113113
if err := json.Unmarshal([]byte(body), &bodyMap); err != nil {
114-
return err
114+
return fmt.Errorf("\n%s\n%s\n", res.Status, body)
115115
}
116116

117117
errorMessage := fmt.Sprintf("\n%s\n", res.Status)

client/controller/client/http_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,36 @@ error: This is an error.
178178
if actual != expected && actual != altExpected {
179179
t.Errorf("Expected %s or %s, Got %s", expected, altExpected, actual)
180180
}
181+
182+
expected = `
183+
503 Service Temporarily Unavailable
184+
<html>
185+
<head><title>503 Service Temporarily Unavailable</title></head>
186+
<body bgcolor="white">
187+
<center><h1>503 Service Temporarily Unavailable</h1></center>
188+
<hr><center>nginx/1.9.4</center>
189+
</body>
190+
</html>
191+
`
192+
193+
body = `<html>
194+
<head><title>503 Service Temporarily Unavailable</title></head>
195+
<body bgcolor="white">
196+
<center><h1>503 Service Temporarily Unavailable</h1></center>
197+
<hr><center>nginx/1.9.4</center>
198+
</body>
199+
</html>`
200+
201+
res = http.Response{
202+
StatusCode: http.StatusServiceUnavailable,
203+
Status: "503 Service Temporarily Unavailable",
204+
}
205+
206+
actual = checkForErrors(&res, body).Error()
207+
208+
if actual != expected {
209+
t.Errorf("Expected %s, Got %s", expected, actual)
210+
}
181211
}
182212

183213
func TestCheckErrorsReturnsNil(t *testing.T) {

0 commit comments

Comments
 (0)