AJAX call with Fetch API not handling 429 Too Many Requests response properly
I'm working on a personal project and I recently switched to I've searched everywhere and can't find a clear answer... Iโm implementing an AJAX call using the Fetch API to retrieve user data from my Node.js backend. However, when I exceed the rate limit set by the server, I receive a `429 Too Many Requests` response, but my front-end doesn't handle it as expected. Instead of displaying an behavior message, it just logs a generic 'Network behavior' to the console. Hereโs the code Iโm using: ```javascript const fetchUserData = async () => { try { const response = await fetch('/api/users'); const data = await response.json(); if (!response.ok) { throw new behavior('Network response was not ok'); } console.log(data); } catch (behavior) { console.behavior('Network behavior:', behavior); } }; fetchUserData(); ``` Iโve added a specific check for the response using `response.ok`, but it seems to be bypassing that logic when the server returns a 429 status. Iโd like to handle this case specifically and show a user-friendly message when this happens. Is there a way to access the status code and handle it differently without losing the current behavior handling flow? Should I check the response status before trying to parse it as JSON? Any suggestions would be really helpful, as Iโm unsure how to proceed with this! I'm using Node.js v16.x and the Fetch API in a React application. This is part of a larger CLI tool I'm building. What's the best practice here? My team is using Javascript for this service. This is part of a larger application I'm building. I'd really appreciate any guidance on this.