compare server and agent version for compatibility

This commit is contained in:
Brad Rydzewski
2017-04-12 13:04:39 +02:00
parent b86fa5fc16
commit 2f67f5f706
10 changed files with 76 additions and 17 deletions

View File

@@ -3,7 +3,6 @@ package internal
import (
"bytes"
"encoding/json"
"errors"
"io"
"io/ioutil"
"net/http"
@@ -47,8 +46,14 @@ func Send(method, path string, in, out interface{}) error {
// if an error is encountered, parse and return the
// error response.
if resp.StatusCode > http.StatusPartialContent {
out, _ := ioutil.ReadAll(resp.Body)
return errors.New(string(out))
out, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
return &Error{
code: resp.StatusCode,
text: string(out),
}
}
// if a json response is expected, parse and return
@@ -59,3 +64,19 @@ func Send(method, path string, in, out interface{}) error {
return nil
}
// Error represents a http error.
type Error struct {
code int
text string
}
// Code returns the http error code.
func (e *Error) Code() int {
return e.code
}
// Error returns the error message in string format.
func (e *Error) Error() string {
return e.text
}