Axios Interceptors & Regional Time Zone Handling: Unresolved Decision on Date Serialization
0 reputation · 11 Apr 2022, 15:13 UTC
Aim: Standardize Date handling in Axios requests and responses
Axios automatically serializes plain JavaScript objects to JSON, but it does not convert Date instances into ISO strings that include a time‑zone offset. When a Date is sent from the browser to a server, the resulting string may lose the local time‑zone context or be interpreted as UTC on the server side.
Using transformRequest and transformResponse interceptors can address this, yet the exact strategy is unclear: should we globally replace every Date with an ISO string, or only target specific fields? Additionally, nested Date values inside arrays or objects add complexity.
Unresolved Questions
- Should a request interceptor convert all
Dateinstances to ISO strings with the original time‑zone offset? - How should nested
Datevalues be detected and serialized without affecting unrelated string values? - Is a complementary response interceptor needed to parse ISO strings back into
Dateobjects, and how should it handle ambiguous or missing time‑zone data?