GUIDE深度 · Deep dive
cURL to fetch/axios Pitfalls
Conversion is not literal: browser fetch is subject to CORS, Node fetch does not carry browser cookies, and axios throws on non-2xx by default. Add timeouts, token refresh and error handling.
Differences
Browsers restrict Host/Cookie/User-Agent headers.
Cross-origin needs server CORS; cURL is not restricted.
Complete the code
Add an AbortController timeout.
Check res.ok; refresh the token on 401.
FAQ
Why does the browser request fail?
Usually CORS/preflight; check the Network panel.
Why does axios throw?
It throws on non-2xx by default; adjust validateStatus.