Skip to content

Commit

Permalink
fix: do not stringify final values that are not explicitly set to `ap…
Browse files Browse the repository at this point in the history
…plication/json` contentType
  • Loading branch information
eyw520 committed Jan 30, 2025
1 parent e68acfc commit 1a5d14b
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ export async function toBodyInit(
for (const [key, value] of Object.entries(body.value)) {
switch (value.type) {
case "json": {
formData.append(
key,
value.contentType
? new Blob([JSON.stringify(value.value)], {
type: value.contentType,
})
: JSON.stringify(value.value)
);
if (value.contentType === "application/json") {
formData.append(
key,
new Blob([JSON.stringify(value.value)], {
type: "application/json",
})
);
} else {
const finalValue =
typeof value.value === "string"
? value.value
: JSON.stringify(value.value);

formData.append(key, finalValue);
}
break;
}
case "file":
Expand Down

0 comments on commit 1a5d14b

Please sign in to comment.