buffer from decoder in unmarshal error
This commit is contained in:
parent
f24f4d512e
commit
c1e9fd594d
11
response.go
11
response.go
@ -87,9 +87,10 @@ func checkFacebookError(r io.Reader) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
qr := QueryResponse{}
|
qr := QueryResponse{}
|
||||||
err = json.NewDecoder(r).Decode(&qr)
|
decoder := json.NewDecoder(r)
|
||||||
|
err = decoder.Decode(&qr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NewUnmarshalError().WithReader(r)
|
return NewUnmarshalError().WithReader(decoder.Buffered())
|
||||||
}
|
}
|
||||||
if qr.Error != nil {
|
if qr.Error != nil {
|
||||||
return xerrors.Errorf("facebook error: %w", qr.Error)
|
return xerrors.Errorf("facebook error: %w", qr.Error)
|
||||||
@ -100,9 +101,9 @@ func checkFacebookError(r io.Reader) error {
|
|||||||
|
|
||||||
func getFacebookQueryResponse(r io.Reader) (QueryResponse, error) {
|
func getFacebookQueryResponse(r io.Reader) (QueryResponse, error) {
|
||||||
qr := QueryResponse{}
|
qr := QueryResponse{}
|
||||||
err := json.NewDecoder(r).Decode(&qr)
|
decoder := json.NewDecoder(r)
|
||||||
if err != nil {
|
if err := decoder.Decode(&qr); err != nil {
|
||||||
return qr, NewUnmarshalError().WithReader(r)
|
return qr, NewUnmarshalError().WithReader(decoder.Buffered())
|
||||||
}
|
}
|
||||||
if qr.Error != nil {
|
if qr.Error != nil {
|
||||||
return qr, xerrors.Errorf("facebook error: %w", qr.Error)
|
return qr, xerrors.Errorf("facebook error: %w", qr.Error)
|
||||||
|
@ -19,13 +19,15 @@ func Test_MarshalStructuredMessageElement(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestResponse_checkFacebookError_UnmarshalError(t *testing.T) {
|
func TestResponse_checkFacebookError_UnmarshalError(t *testing.T) {
|
||||||
r := bytes.NewReader([]byte("test"))
|
r := bytes.NewReader([]byte("test error text"))
|
||||||
err := checkFacebookError(r)
|
err := checkFacebookError(r)
|
||||||
assert.True(t, errors.Is(err, ErrUnmarshal))
|
assert.True(t, errors.Is(err, ErrUnmarshal))
|
||||||
|
assert.Contains(t, err.Error(), "test error text")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResponse_getFacebookQueryResponse_UnmarshalError(t *testing.T) {
|
func TestResponse_getFacebookQueryResponse_UnmarshalError(t *testing.T) {
|
||||||
r := bytes.NewReader([]byte("test"))
|
r := bytes.NewReader([]byte("test error text"))
|
||||||
_, err := getFacebookQueryResponse(r)
|
_, err := getFacebookQueryResponse(r)
|
||||||
assert.True(t, errors.Is(err, ErrUnmarshal))
|
assert.True(t, errors.Is(err, ErrUnmarshal))
|
||||||
|
assert.Contains(t, err.Error(), "test error text")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user