forked from TrueCloudLab/rclone
rc: return error from remote on failure
This commit is contained in:
parent
6607d8752c
commit
3d8e529441
1 changed files with 15 additions and 1 deletions
16
cmd/rc/rc.go
16
cmd/rc/rc.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -39,7 +40,7 @@ Arguments should be passed in as parameter=value.
|
||||||
|
|
||||||
The result will be returned as a JSON object by default.
|
The result will be returned as a JSON object by default.
|
||||||
|
|
||||||
Use "rclone rc list" to see a list of all possible commands.`,
|
Use "rclone rc" to see a list of all possible commands.`,
|
||||||
Run: func(command *cobra.Command, args []string) {
|
Run: func(command *cobra.Command, args []string) {
|
||||||
cmd.CheckArgs(0, 1E9, command, args)
|
cmd.CheckArgs(0, 1E9, command, args)
|
||||||
cmd.Run(false, false, command, func() error {
|
cmd.Run(false, false, command, func() error {
|
||||||
|
@ -80,6 +81,19 @@ func doCall(path string, in rc.Params) (out rc.Params, err error) {
|
||||||
}
|
}
|
||||||
defer fs.CheckClose(resp.Body, &err)
|
defer fs.CheckClose(resp.Body, &err)
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
var body []byte
|
||||||
|
body, err = ioutil.ReadAll(resp.Body)
|
||||||
|
var bodyString string
|
||||||
|
if err == nil {
|
||||||
|
bodyString = string(body)
|
||||||
|
} else {
|
||||||
|
bodyString = err.Error()
|
||||||
|
}
|
||||||
|
bodyString = strings.TrimSpace(bodyString)
|
||||||
|
return nil, errors.Errorf("Failed to read rc response: %s: %s", resp.Status, bodyString)
|
||||||
|
}
|
||||||
|
|
||||||
// Parse output
|
// Parse output
|
||||||
out = make(rc.Params)
|
out = make(rc.Params)
|
||||||
err = json.NewDecoder(resp.Body).Decode(&out)
|
err = json.NewDecoder(resp.Body).Decode(&out)
|
||||||
|
|
Loading…
Add table
Reference in a new issue