Skip to content

Commit

Permalink
fix:on post request post a empty body
Browse files Browse the repository at this point in the history
  • Loading branch information
superAlibi committed Sep 17, 2024
1 parent 26702b8 commit ba41caf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@advanced/fetcher",
"version": "1.0.5",
"version": "1.0.6",
"exports": "./mod.ts",
"license": "MIT",
"publish": {
Expand Down
6 changes: 3 additions & 3 deletions libs/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ export class Fetcher extends SyncEventDispatcher<{
}
const { headers } = otherCustomConfig || {}
const contentType = Object.fromEntries(Object.entries(headers || {}).map(([k, v]) => [k.toLowerCase(), v]))['content-type'];
let formatedbody: BodyInit | undefined
if (contentType?.toLowerCase()?.includes('application/json')) {
try {
formatedbody = JSON.stringify(body)
return new Request(urlObj, { ...otherCustomConfig, body: JSON.stringify(body) })

} catch {

throw new Error(`body must be json stringify,but got ${typeof body}`)
}
}

return new Request(urlObj, { ...otherCustomConfig, body: formatedbody })
return new Request(urlObj, { ...otherCustomConfig, body: body as BodyInit })
}
/**
* 构建响应体
Expand Down

0 comments on commit ba41caf

Please sign in to comment.