Skip to content

Commit fef1e35

Browse files
Copilotlikui628
andauthored
fix: prevent JSONBigInt parsing error on non-string data (#6891)
* Initial plan * Fix json-bigint serialization error when data is not a string Co-authored-by: likui628 <90845831+likui628@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: likui628 <90845831+likui628@users.noreply.github.com>
1 parent 20410ae commit fef1e35

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

playground/src/api/request.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ function createRequestClient(baseURL: string, options?: RequestClientOptions) {
2929
baseURL,
3030
transformResponse: (data: any, header: AxiosResponseHeaders) => {
3131
// storeAsString指示将BigInt存储为字符串,设为false则会存储为内置的BigInt类型
32-
return header.getContentType()?.toString().includes('application/json')
33-
? cloneDeep(
34-
JSONBigInt({ storeAsString: true, strict: true }).parse(data),
35-
)
36-
: data;
32+
if (
33+
header.getContentType()?.toString().includes('application/json') &&
34+
typeof data === 'string'
35+
) {
36+
return cloneDeep(
37+
JSONBigInt({ storeAsString: true, strict: true }).parse(data),
38+
);
39+
}
40+
return data;
3741
},
3842
});
3943

0 commit comments

Comments
 (0)