mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-18 20:23:28 +02:00
Support empty responses in request commands
Avoid JSON parser when the response is empty - common cases for HTTP 204 in issues deletion, or moving issues to sprint.
This commit is contained in:
committed by
Louis DeLosSantos
parent
ff5decc114
commit
b572037cfe
+11
-2
@@ -3,12 +3,12 @@ package jiracmd
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
"github.com/coryb/oreo"
|
||||
|
||||
"github.com/go-jira/jira/jiracli"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
@@ -74,8 +74,17 @@ func CmdRequest(o *oreo.Client, globals *jiracli.GlobalOptions, opts *RequestOpt
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
bodyBytes, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Response Body read Error: %v", err)
|
||||
}
|
||||
if len(bodyBytes) == 0 {
|
||||
log.Info("Empty response for status %d", resp.StatusCode)
|
||||
return nil
|
||||
}
|
||||
|
||||
var data interface{}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
|
||||
if err := json.Unmarshal(bodyBytes, &data); err != nil {
|
||||
return fmt.Errorf("JSON Parse Error: %v", err)
|
||||
}
|
||||
return opts.PrintTemplate(&data)
|
||||
|
||||
Reference in New Issue
Block a user