Skip to content

Commit

Permalink
rest: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Gorniaky committed Sep 10, 2023
1 parent c941290 commit 7c8185c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/rest/src/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface RequestData {
/**
* The body to send to this request.
*/
body?: BodyInit
body?: BodyInit | unknown
/**
* The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} to use for the request.
*/
Expand Down
15 changes: 13 additions & 2 deletions packages/rest/src/RequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,21 @@ export class RequestManager extends EventEmitter {

if (request.body)
if (request.file) {
for (const [key, value] of Object.entries(request.body))
if (typeof request.body === "string")
try {
request.body = JSON.parse(request.body);
} catch {
request.body = {};
}

for (const [key, value] of Object.entries(<any>request.body))
formData.append(key, value);
} else {
fetchOptions.body = JSON.stringify(request.body);
if (typeof request.body === "string") {
fetchOptions.body = request.body;
} else {
fetchOptions.body = JSON.stringify(request.body);
}
}

if (request.file) fetchOptions.body = formData;
Expand Down

0 comments on commit 7c8185c

Please sign in to comment.