When replacing body
in beforeRequest
hook with a data that contains Unicode characters, an error may occur.
https://codesandbox.io/p/sandbox/hungry-dew-gd283f?file=%2Fapp%2Fpage.tsx%3A18%2C13-18%2C69
got
.post("domain.api", {
hooks: {
beforeRequest: [
(options) => {
const newJsonBody = {
...options.json,
new_field: "new_field",
};
// Original: not working
options.body = JSON.stringify(newJsonBody);
// Fixed
// options.body = Buffer.from(JSON.stringify(newJsonBody));
options.headers["content-length"] = options.body.length.toString();
},
],
},
json: {
city: "Hà Nội", // Unicode characters
},
})
I found a solution by using a Buffer
instead. It may be useful to update the documentation to reflect this approach.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too