-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from sdss/albireox/json-bigint
Use json-big to parse main query response
- Loading branch information
Showing
3 changed files
with
41 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import axios from 'axios' | ||
import JSONbig from 'json-big' | ||
|
||
// Defines the API instance in Axios with special handling for big integers. | ||
const axiosInstance = axios.create({ | ||
baseURL: import.meta.env.VITE_API_URL, | ||
timeout: 5000, | ||
transformResponse: [ | ||
function transform(data) { | ||
// Replacing the default transformResponse in axios because this uses JSON.parse and causes problems | ||
// with precision of big numbers. | ||
if (typeof data === 'string') { | ||
try { | ||
data = JSONbig.parse(data) | ||
} catch (e) { | ||
/* Ignore */ | ||
} | ||
} | ||
return data | ||
} | ||
] | ||
}) | ||
|
||
export default axiosInstance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters