1
0
Fork 0

Actually check HTTP status codes

master
Philip O'Toole 1 year ago
parent 62fd272897
commit 735c4cbc19

@ -394,6 +394,9 @@ func (n *Node) postExecute(stmt string) (string, error) {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("execute endpoint returned: %s", resp.Status)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
@ -412,6 +415,9 @@ func (n *Node) postExecuteQueued(stmt string, wait bool) (string, error) {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("execute endpoint (queued) returned: %s", resp.Status)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
@ -431,6 +437,9 @@ func (n *Node) query(stmt, consistency string) (string, error) {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("query endpoint returned: %s", resp.Status)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
@ -444,6 +453,9 @@ func (n *Node) postQuery(stmt string) (string, error) {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("query endpoint (POST) returned: %s", resp.Status)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
@ -457,6 +469,9 @@ func (n *Node) postRequest(stmt string) (string, error) {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("request endpoint returned: %s", resp.Status)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
@ -481,6 +496,9 @@ func PostExecuteStmtMulti(apiAddr string, stmts []string) (string, error) {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("execute endpoint returned: %s", resp.Status)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err

Loading…
Cancel
Save