Skip to content
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

fix: double decoding of json #319

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(';');
manchuck marked this conversation as resolved.
Show resolved Hide resolved
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
Loading