-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http: Improve Response html()/json() error message if body is null #2195
http: Improve Response html()/json() error message if body is null #2195
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @daniel-shuy,
thanks for your contribution! 🎉 👏
It would be good if we can add some test coverage for these cases.
js/modules/k6/http/response.go
Outdated
@@ -72,14 +72,21 @@ func (h *HTTP) responseFromHttpext(resp *httpext.Response) *Response { | |||
|
|||
// HTML returns the body as an html.Selection | |||
func (res *Response) HTML(selector ...string) html.Selection { | |||
rt := common.GetRuntime(res.GetCtx()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need it, in this way, we are making this call also in the positive cases that it shouldn't be necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I've reverted it
@codebien I've added tests as you suggested, using httpbin's /status/{codes} to simulate an empty response body |
@daniel-shuy the tests are failing, You could test using
or re-assigning the body
|
@codebien using I still can't figure out why
|
Codecov Report
@@ Coverage Diff @@
## master #2195 +/- ##
==========================================
+ Coverage 72.71% 72.79% +0.07%
==========================================
Files 184 184
Lines 14571 14671 +100
==========================================
+ Hits 10596 10680 +84
- Misses 3333 3343 +10
- Partials 642 648 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also rebase the history squashing the fixups commits on the first commit, please? In this way, it will be easier for the next reviewer to check it. Thanks
6e59713
to
8666d19
Compare
Sure, I usually prefer to squash after its approved so that only the changes need to be re-reviewed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉 let's wait @imiric's review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @daniel-shuy!
LGTM, just a suggestion to fix the casing on HTML/JSON and to concatenate the error message to avoid silencing the linter. The concatenation should be negligible and it's also more readable in the code IMO.
8666d19
to
7d00c3e
Compare
7d00c3e
to
8967a65
Compare
@imiric done, thanks! |
Closes #2188
When Response.body is
nil
, instead of displaying the error messageinvalid type <nil>, expected string, []byte or ArrayBuffer
(which is being propagated fromutil.ToBytes()
/util.ToString()
),Response.html()
displaysthe body is null so we can't transform it to html - this likely was because of a request error getting the response
whileResponse.json()
displaysthe body is null so we can't transform it to json - this likely was because of a request error getting the response
.