Skip to content

Commit 1d6ef0c

Browse files
committed
Handle BigInt numbers from API
1 parent cc259d6 commit 1d6ef0c

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

packages/react-api/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
"webpack-cli": "^4.5.0"
6666
},
6767
"dependencies": {
68-
"@babel/runtime": "^7.13.9"
68+
"@babel/runtime": "^7.13.9",
69+
"json-bigint": "^1.0.0"
6970
},
7071
"peerDependencies": {
7172
"@carto/react-core": "^3.1.0-alpha.1",

packages/react-api/src/api/common.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { InvalidColumnError } from '@carto/react-core/';
2+
import JSONbig from 'json-bigint';
23

34
/**
45
* Return more descriptive error from API
@@ -51,7 +52,10 @@ export async function makeCall({ url, credentials, opts }) {
5152
signal: opts?.abortController?.signal,
5253
...opts?.otherOptions
5354
});
54-
data = await response.json();
55+
56+
// Parse with JSONbig to automatically handle large numbers as BigInt
57+
const text = await response.text();
58+
data = JSONbig.parse(text);
5559
} catch (error) {
5660
if (error.name === 'AbortError') throw error;
5761

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12430,6 +12430,13 @@ json-bigint@^0.3.0:
1243012430
dependencies:
1243112431
bignumber.js "^9.0.0"
1243212432

12433+
json-bigint@^1.0.0:
12434+
version "1.0.0"
12435+
resolved "https://registry.yarnpkg.com/json-bigint/-/json-bigint-1.0.0.tgz#ae547823ac0cad8398667f8cd9ef4730f5b01ff1"
12436+
integrity sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==
12437+
dependencies:
12438+
bignumber.js "^9.0.0"
12439+
1243312440
json-buffer@3.0.0:
1243412441
version "3.0.0"
1243512442
resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.0.tgz#5b1f397afc75d677bde8bcfc0e47e1f9a3d9a898"

0 commit comments

Comments
 (0)