mirror of
https://github.com/asticode/go-astikit.git
synced 2025-12-24 11:50:53 +08:00
Now logging json when unmarshal fails
This commit is contained in:
13
http.go
13
http.go
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -244,8 +245,16 @@ func (s *HTTPSender) SendJSON(o HTTPSendJSONOptions) (err error) {
|
||||
|
||||
// Unmarshal body out
|
||||
if o.BodyOut != nil {
|
||||
if err = json.NewDecoder(resp.Body).Decode(o.BodyOut); err != nil {
|
||||
err = fmt.Errorf("astikit: unmarshaling failed: %w", err)
|
||||
// Read all
|
||||
var b []byte
|
||||
if b, err = ioutil.ReadAll(resp.Body); err != nil {
|
||||
err = fmt.Errorf("astikit: reading all failed: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Unmarshal
|
||||
if err = json.Unmarshal(b, o.BodyOut); err != nil {
|
||||
err = fmt.Errorf("astikit: unmarshaling failed: %w (json: %s)", err, b)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user