From 3d8e529441a92834fbd637279bd1a346762c5f99 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 29 May 2018 10:45:59 +0100 Subject: [PATCH] rc: return error from remote on failure --- cmd/rc/rc.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/rc/rc.go b/cmd/rc/rc.go index 73f9a49b9..cdfec97af 100644 --- a/cmd/rc/rc.go +++ b/cmd/rc/rc.go @@ -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)