Skip to content

Commit 9972c74

Browse files
committed
fix(client): show HTTP status first on errors
1 parent 20b64c2 commit 9972c74

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

client/controller/client/http.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,16 @@ func checkForErrors(res *http.Response, body string) error {
114114
return err
115115
}
116116

117-
errorMessage := "\n"
117+
errorMessage := fmt.Sprintf("\n%s\n", res.Status)
118118
for key, value := range bodyMap {
119119
switch v := value.(type) {
120120
case string:
121-
errorMessage += key + ": " + v + "\n"
121+
errorMessage += fmt.Sprintf("%s: %s\n", key, v)
122122
case []interface{}:
123123
for _, subValue := range v {
124124
switch sv := subValue.(type) {
125125
case string:
126-
errorMessage += key + ": " + sv + "\n"
126+
errorMessage += fmt.Sprintf("%s: %s\n", key, sv)
127127
default:
128128
fmt.Printf("Unexpected type in %s error message array. Contents: %v",
129129
reflect.TypeOf(value), sv)
@@ -135,7 +135,6 @@ func checkForErrors(res *http.Response, body string) error {
135135
}
136136
}
137137

138-
errorMessage += res.Status + "\n"
139138
return errors.New(errorMessage)
140139
}
141140

client/controller/client/http_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,16 @@ func TestCheckErrors(t *testing.T) {
147147
t.Parallel()
148148

149149
expected := `
150+
404 NOT FOUND
150151
error: This is an error.
151152
error_array: This is an array.
152153
error_array: Foo!
153-
404 NOT FOUND
154154
`
155155
altExpected := `
156+
404 NOT FOUND
156157
error_array: This is an array.
157158
error_array: Foo!
158159
error: This is an error.
159-
404 NOT FOUND
160160
`
161161

162162
body := `

0 commit comments

Comments
 (0)