Common Swiggy API Errors in React Projects and How to Resolve Them
A list of the common errors you hit when using the Swiggy API in React, and exactly how to resolve each.
Common Swiggy API Errors in React Projects and How to Resolve Them
Using the Swiggy API in a React project surfaces a predictable set of errors. Here are the most common ones and how to resolve each.
CORS Error
The browser blocks the request because the API does not allow your origin. Resolve with a development proxy or by calling through a small backend.
'map is not a function'
Your code expects an array but the response is an object. The data is likely nested. Log the response, find the array inside it, and update your parsing.
Network Error
The request never reaches the API. Check your internet connection, look for a typo in the URL, and rule out a VPN or firewall blocking the domain.
429 Too Many Requests
You are calling the API too often. Cache responses and reduce call frequency. Rate limiting is common with free and dummy APIs.
404 Not Found
The endpoint changed or you have a typo. Verify the URL against the latest documentation and update your code.
Stale Data After Navigation
You see old data after navigating back. The fetch is using a cached response or not refetching on route change. Refetch when the route parameter changes by including it in the dependency array.
Updating State After Unmount
You see a warning about updating state on an unmounted component. Use a cleanup flag or abort signal to cancel the fetch on unmount.
The Takeaway
Most Swiggy API errors fall into these categories: CORS, response shape, network, rate limiting, stale data, and unmount. Knowing the fix for each turns panic into routine.
Use a development proxy in your bundler config or a small backend proxy. The proxy forwards the request server-side, bypassing the browser's CORS restrictions for local development.
Because your code expects an array but the response is an object with the array nested inside. Log the full response, find the array in the correct field, and update your parsing to extract it before calling map.
It means you are calling the API too often and are being rate-limited. Cache responses so you do not re-request the same data, and reduce the frequency of your calls.
Because the fetch is using a cached response or not refetching on route change. Include the route parameter in the useEffect dependency array so the fetch re-runs when the route changes.
Use a cleanup flag that tracks whether the component is still mounted, or an AbortController to cancel the fetch on unmount. Only update state if the component is still mounted.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

