May I ask where the backend is hosted?
This behavior typically isn’t a code issue as many free or low-tier hosting services automatically suspend your app after being idle for sometime.
The first request after a long idle period usually fails because it’s waking up the server ‘cold start’ if you want to put it that way, and requests that follow works fine once the instance of your server is active again.