Skip to content

Commit

Permalink
Merge pull request #17 from quobyte/handle-http-replies
Browse files Browse the repository at this point in the history
More explicit error reporting on HTTP issues in JsonRPC
  • Loading branch information
casusbelli authored Feb 20, 2019
2 parents 9cfd293 + 8a6f432 commit 2a784af
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"log"
"math/rand"
"net/http"
Expand Down Expand Up @@ -112,7 +113,17 @@ func (client QuobyteClient) sendRequest(method string, request interface{}, resp
defer resp.Body.Close()

if resp.StatusCode < 200 || resp.StatusCode > 299 {
log.Printf("Warning: HTTP status code for request is %s\n", strconv.Itoa(resp.StatusCode))
log.Printf("Warning: HTTP status code for request is %s\n",
strconv.Itoa(resp.StatusCode))
if resp.StatusCode == 401 {
return errors.New("Unable to authenticate with Quobyte API service")
}
body, err := io.ioutil.ReadAll(resp.Body)
if err != nil {
return (err)
}
log.Printf("Warning: Dumping full reply body:\n%s\n", string(body))
return errors.New("JsonRPC failed, see plugin logfile for details")
}
return decodeResponse(resp.Body, &response)
}

0 comments on commit 2a784af

Please sign in to comment.