Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!