Skip to content

Commit

Permalink
Issue #18: Unmarshaling error of result data should be reported
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas committed Sep 26, 2024
1 parent 5a4975f commit eb5a3c1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func Send(options *Options, results interface{}) (*Content, error) {
log.Tracef("Response body in %s: %s", time.Since(start), resContent.LogString(uint64(options.ResponseBodyLogSize)))
err = json.Unmarshal(resContent.Data, results)
if err != nil {
log.Debugf("Failed to unmarshal response body, use the Content, JSON Error: %s", err)
return resContent, errors.JSONUnmarshalError.WrapIfNotMe(err)
}
return resContent, nil
}
Expand Down
10 changes: 6 additions & 4 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ func (suite *RequestSuite) TestCanSendRequestWithResults() {
suite.Assert().Equal(1234, results.Code, "Results should have been received and decoded")
}

func (suite *RequestSuite) TestCanSendRequestWithResultsAndInvalidData() {
func (suite *RequestSuite) TestShouldFailWithInvalidDataAsResults() {
serverURL, _ := url.Parse(suite.Server.URL)
serverURL, _ = serverURL.Parse("/")
results := struct {
Expand All @@ -504,10 +504,12 @@ func (suite *RequestSuite) TestCanSendRequestWithResultsAndInvalidData() {
URL: serverURL,
Logger: suite.Logger,
}, &results)
suite.Require().NoError(err, "Failed sending request, err=%+v", err)
suite.Require().Error(err, "Failed sending request, err=%+v", err)
suite.T().Logf("Expected Error: %+v", err)
suite.Logger.Errorf("Expected Error", err)
suite.Require().ErrorIs(err, errors.JSONUnmarshalError, "Error should be a JSON Unmarshal error")
suite.Require().NotNil(content, "Content should not be nil")
suite.Assert().Equal(0, results.Code, "Results should not have been decoded")
suite.Assert().Equal("body", string(content.Data))
suite.Logger.Infof("Body: %s", content.Data)
}

func (suite *RequestSuite) TestCanSendRequestWithToken() {
Expand Down

0 comments on commit eb5a3c1

Please sign in to comment.