mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-22 05:47:57 +00:00
compare server and agent version for compatibility
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user