-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: fixed BigInt sent as json #1773
Conversation
7d1fcec
to
259a43f
Compare
v8.1.0 released which fixes this issue, thank you
release notes @ https://github.com/ladjs/superagent/releases/tag/v8.1.0 |
This broke some code I'm working on, where I use BigInt.prototype.toJSON = function (key, value) {
return String(this);
}; to generally make |
Is there a way you could do a PR or something to fix this @bjornua? |
Sure, I'll have a look |
Checklist
Problem
Inspired by this issue: #1769
When a value containing primitive type BigInt is sent with type set to json, the error message is sent in the request body. I believe that this kind of error should be caught before the request is sent out, so that errors can be handled internally.
The error occurs when a BigInt or object containing a BigInt is sent with type set to json, 2 examples below:
Previous behavior:
JSON error occurs, but the error message is sent in the body of the request regardless. I have a local mockoon server running on the left where you can see what was received by the server.
Behavior after this PR:
Error is thrown if BigInt is found in the .send() method, error not sent to server
Error: Cannot serialize BigInt value to json at RequestBase.send (F:\superagent-test\node_modules\superagent\lib\request-base.js:616:47) at testAsync (file:///F:/superagent-test/index.js:26:14) at file:///F:/superagent-test/index.js:43:7 at ModuleJob.run (node:internal/modules/esm/module_job:185:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:281:24) at async loadESM (node:internal/process/esm_loader:88:5) at async handleMainPromise (node:internal/modules/run_main:65:12)
It's my first time with an open-source contribution so let me know what you would like changed and I'd be happy to do it!