Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post set content-length error #1730

Open
sherryhhx opened this issue Jun 13, 2022 · 2 comments
Open

post set content-length error #1730

sherryhhx opened this issue Jun 13, 2022 · 2 comments

Comments

@sherryhhx
Copy link

No description provided.

@sherryhhx
Copy link
Author

The "string" argument must be of type string or an instance of Buffer or ArrayBuffer.
Received an instance of Object at Function.byteLength (buffer.js:724:11)
at Request._end (xxxx/node_modules/superagent/lib/node/index.js:804:84)
at Request.end (xxx/node_modules/superagent/lib/node/index.js:777:15)

@sherryhhx sherryhhx changed the title post set content-length bug post set content-length error Jun 13, 2022
@Woodz
Copy link

Woodz commented Jul 16, 2024

To clarify this bug, this happens when trying to call .send with an object, e.g.

await request(app.getHttpServer())
            .post('/foo/bar')
            .send({a: 1});

The workaround is to call JSON.stringify on the payload, e.g.

await request(app.getHttpServer())
            .post('/foo/bar')
            .send(JSON.stringify({a: 1}));

Superagent should catch this by tightening TS typing and should have a nicer error message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants