-
Notifications
You must be signed in to change notification settings - Fork 80
fix(api): correctly handle responses with missing content-type header #112
Conversation
Also prevents non .tgz requests from being handled as tgz requests — the previous if condition was incorrect
Codecov Report
@@ Coverage Diff @@
## master #112 +/- ##
==========================================
+ Coverage 71.16% 71.28% +0.11%
==========================================
Files 88 88
Lines 874 874
Branches 156 156
==========================================
+ Hits 622 623 +1
+ Misses 240 239 -1
Partials 12 12
Continue to review full report at Codecov.
|
return Promise.all([response.ok, response.text()]); | ||
} | ||
|
||
// unfortunatelly on download files there is no header available | ||
if (response.url && response.url.endsWith('.tgz') !== null) { | ||
if (response.url && response.url.endsWith('.tgz') === true) { |
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.
That's right, it must to be true
.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith#Return_value
|
||
const handled = await handleResponseType(response); | ||
|
||
// Should this actually return [false, null] ? |
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.
According the fetch
https://developer.mozilla.org/en-US/docs/Web/API/Response#Properties docs the Response
. The first part of the array should be boolean and thus as second argument a the promise resolved according the type blob
etc etc ...
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 so much for this and 👏 for the unit test !
Also prevents non .tgz requests from being handled as tgz requests — the previous if condition was incorrect
Type: bug
The following has been addressed in the PR:
Description:
Previously if for whatever reason an API request resulted in a 400 error without a content-type header, then this code would fail, as it was trying to call
includes
onnull
, resulting in what looked like a plugin/configuration error. Additionally, I noticed in testing that the check for handling.tgz
files was incorrect, and it should've beenrequest.url.includes('.tgz') === true
rather than!== null
, though I'm not sure the best way to test that.