Skip to content

Commit

Permalink
fix: using json.Unmarshal
Browse files Browse the repository at this point in the history
  • Loading branch information
christopher-besch committed Jun 5, 2024
1 parent 8c40f10 commit 4d0a1d8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions onpremise/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"reflect"
Expand Down Expand Up @@ -288,6 +289,7 @@ func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) {
if err != nil {
return nil, err
}
defer httpResp.Body.Close()

err = CheckResponse(httpResp)
if err != nil {
Expand All @@ -298,8 +300,11 @@ func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) {

if v != nil {
// Open a NewDecoder and defer closing the reader only if there is a provided interface to decode to
defer httpResp.Body.Close()
err = json.NewDecoder(httpResp.Body).Decode(v)
body, err := ioutil.ReadAll(httpResp.Body)
if err != nil {
return newResponse(httpResp, nil), err
}
err = json.Unmarshal(body, v)
}

resp := newResponse(httpResp, v)
Expand Down

0 comments on commit 4d0a1d8

Please sign in to comment.