Skip to content

Commit

Permalink
fix: double decoding of json (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
manchuck authored Jan 29, 2024
1 parent 7a2a65e commit ee9eb27
Show file tree
Hide file tree
Showing 3 changed files with 953 additions and 958 deletions.
10 changes: 4 additions & 6 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ const api = ({
const bodyText = await response.text();
let body = bodyText;

switch (response.headers.get('content-type')) {
const [contentType] = (response.headers.get('content-type') || '').split(';');
switch (contentType) {
case 'application/x-www-form-urlencoded':
body = response.body
? new URLSearchParams(body)
Expand Down Expand Up @@ -312,9 +313,7 @@ Client.prototype.listBroadcasts = function listBroadcasts(queryString, cb) {
url:url,
method: 'GET',
headers: this.generateHeaders(),
callback: (err, response ) => {
const items = response ? JSON.parse(response) : response;

callback: (err, items) => {
cb(
err,
items?.items.map((item) => new Broadcast(Client, JSON.stringify(item))),
Expand Down Expand Up @@ -410,8 +409,7 @@ Client.prototype.listStreams = function listStreams(sessionId, cb) {
url: url,
method: 'GET',
headers: this.generateHeaders(),
callback: (err, response) => {
const body = response ? JSON.parse(response) : response;
callback: (err, body) => {
cb(err, body?.items.map((stream) => new Stream(JSON.stringify(stream))))
},
});
Expand Down
Loading

0 comments on commit ee9eb27

Please sign in to comment.