sdss / zora

Web app for SDSS-V
1 stars 0 forks source link

Use json-big to parse main query response #24

Closed albireox closed 4 months ago

albireox commented 4 months ago

Related to sdss/valis#23.

This PR modifies how the response JSON from the API query for the main search page is parsed. Normally big integers are not preserved when parsin JSON; instead they are cast to float and then back to integer, which causes rounding errors. Using json-bigint solves this issue.

See here for more details. I haven't confirmed if there are other places in which this transformation need to be done.

albireox commented 4 months ago

I've kept json-big since I don't think there are big (pun intended) differences.

Have a look at the new commits I made. I've moved the configuration of the axios instance to an api.ts file (the name and location can change) where the JSON bigint handling is done. Then you can use that instance to do API requests and it's not necessary to do the same bigint configuration each time. I used a 5 second timeout which may be insufficient in some cases.

I made this change for Target and Search but there may be other places that need it. I did a bit of testing and it seems to work but it would be good if you can test independently. The docs for the axios instance are here

https://axios-http.com/docs/instance

havok2063 commented 4 months ago

Actually, to keep this PR focused on the main query, we don't need to replace all instances of axios. We can do that in a later PR. I'll create a new issue for it. I'll need to add global custom headers for the authentication to this config anyways

albireox commented 4 months ago

I agree, let's do that as a different PR, but I'll add myself to #25. And I'll write some tests; I'm actually interested in learning how to test JS and I see you have some examples there.

havok2063 commented 4 months ago

Looks good to me!