fix endpoints

This commit is contained in:
2023-03-23 18:44:14 +01:00
parent 3fb66e075d
commit b6dfafd1c1
8 changed files with 59 additions and 51 deletions

View File

@@ -135,11 +135,6 @@ func HandleResponse(c *cfg.Config, resp *req.Response) error {
// we expect a json response, extract the error, if any
r := Response{}
if err := json.Unmarshal([]byte(resp.String()), &r); err != nil {
// text output!
r.Message = resp.String()
}
if c.Debug {
trace := resp.Request.TraceInfo()
fmt.Println(trace.Blame())
@@ -147,6 +142,15 @@ func HandleResponse(c *cfg.Config, resp *req.Response) error {
fmt.Println(trace)
}
if !resp.IsSuccessState() {
return fmt.Errorf("bad response: %s", resp.Status)
}
if err := json.Unmarshal([]byte(resp.String()), &r); err != nil {
// text output!
r.Message = resp.String()
}
if !r.Success {
if len(r.Message) == 0 {
if resp.Err != nil {
@@ -200,7 +204,7 @@ func UploadFiles(w io.Writer, c *cfg.Config, args []string) error {
}
func List(w io.Writer, c *cfg.Config, args []string) error {
rq := Setup(c, "/list/")
rq := Setup(c, "/uploads")
params := &ListParams{Apicontext: c.Apicontext}
resp, err := rq.R.
@@ -245,7 +249,7 @@ func Describe(w io.Writer, c *cfg.Config, args []string) error {
id := args[0] // we describe only 1 object
rq := Setup(c, "/upload/"+id+"/")
rq := Setup(c, "/uploads/"+id+"/")
resp, err := rq.R.Get(rq.Url)
if err != nil {
@@ -266,7 +270,7 @@ func Download(w io.Writer, c *cfg.Config, args []string) error {
id := args[0]
rq := Setup(c, "/uploads/"+id+"/")
rq := Setup(c, "/uploads/"+id+"/file")
if !c.Silent {
// progres bar
@@ -289,6 +293,10 @@ func Download(w io.Writer, c *cfg.Config, args []string) error {
return err
}
if !resp.IsSuccessState() {
return fmt.Errorf("bad response: %s", resp.Status)
}
_, params, err := mime.ParseMediaType(resp.Header.Get("Content-Disposition"))
if err != nil {
os.Remove(id)