mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 17:14:44 +01:00
rc: return error from remote on failure
This commit is contained in:
parent
6607d8752c
commit
3d8e529441
16
cmd/rc/rc.go
16
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)
|
||||
|
Loading…
Reference in New Issue
Block a user