Skip to content

Commit 5eda64f

Browse files
committed
Use the statusMessage only if there's a failure to get the actual message.
When there's an error, the status message is generated by the http server, and has a form like "400 Bad Request". If we fail to read the actual message from the response.body, only then do we actually display the status message. It's also displayed for unexpected error codes (not 400, 401, or 500), because there's nothing from the command-server to display. Signed-off-by: Eric Promislow <[email protected]>
1 parent f1275b9 commit 5eda64f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/go/rdctl/cmd/root.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ func doRestOfRequest(req *http.Request) ([]byte, error) {
117117
if response.StatusCode < 200 || response.StatusCode >= 300 {
118118
switch response.StatusCode {
119119
case 400:
120-
// Use the error message in the body written by the command-server, not the one from the http server.
120+
statusMessage = response.Status
121+
// Prefer the error message in the body written by the command-server, not the one from the http server.
121122
break
122123
case 401:
123124
return nil, fmt.Errorf("user/password not accepted")
@@ -137,7 +138,7 @@ func doRestOfRequest(req *http.Request) ([]byte, error) {
137138
}
138139
return nil, err
139140
} else if statusMessage != "" {
140-
return nil, fmt.Errorf("%s: %s", statusMessage, string(body))
141+
return nil, fmt.Errorf("%s", string(body))
141142
}
142143

143144
return body, nil

0 commit comments

Comments
 (0)