1
mirror of https://github.com/rclone/rclone synced 2024-09-15 11:38:53 +02:00

rc: return error from remote on failure

This commit is contained in:
Nick Craig-Wood 2018-05-29 10:45:59 +01:00
parent 6607d8752c
commit 3d8e529441

View File

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
@ -39,7 +40,7 @@ Arguments should be passed in as parameter=value.
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) {
cmd.CheckArgs(0, 1E9, command, args)
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)
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
out = make(rc.Params)
err = json.NewDecoder(resp.Body).Decode(&out)