Skip to content
Closed
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
21 changes: 20 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,26 @@ export class API {
body: passbody,
});

const data = await fetchdata[config?.responseType || "json"]();
let data: any;
const text = await fetchdata.text();
if (text) {
switch (config?.responseType || "json") {
case "json":
data = JSON.parse(text);
break;
case "text":
data = text;
break;
case "blob":
data = new Blob([text]);
break;
case "arrayBuffer":
data = new TextEncoder().encode(text).buffer;
break;
}
} else {
data = null;
}
Comment on lines -208 to +227
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the blob/arrayBuffer cases (although not used) are prone to error here.
I'm not sure if it's a good idea to go straight to text..


if (fetchdata.ok) {
return data;
Expand Down