Skip to content

Commit

Permalink
Merge pull request #8 from aduyng/fix-204-JSON-parsing-issue
Browse files Browse the repository at this point in the history
fixed the 204 JSON parsing issue
  • Loading branch information
lpg2709 authored Jun 12, 2023
2 parents 75e8605 + b8187a8 commit 8334c0f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/utils/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,21 @@ module.exports = {
if (res.statusCode != 204) {
reject(res.statusCode);
}

// 204 should not return any data, but if it does, we'll parse it
res.on('data', function (chunk) {
str += chunk;
});

res.on('end', function () {
resolve(JSON.parse(str));
let parsedJSON = null;
try {
parsedJSON = JSON.parse(str);
}
catch (e) {
// ignore the error for now
}

resolve(parsedJSON);
});

res.on('error', function (err) {
Expand Down

0 comments on commit 8334c0f

Please sign in to comment.