Type Error: Failed to fetch, how to debug?
Unanswered
Tomistoma posted this in #help-forum
TomistomaOP
Dear NextJS-Community,
we got a weird issue in a project we don't know how to approach the debug, and we hope to get some new ideas from you. The Setup is a NextJS-Frontend hosted on Vercel, the Backend is a Symfony PHP Backend hosted on AWS. The Backend provides a pretty standard REST API, which in 95% we call via server-actions.
In one special case, we rely on direct calls from client to API directly, because we do not want to trigger any rerenderings of server-components whatsoever, and making requests with server-actions always produces these kind of sideeffects.
Most of the times this works without issues, but very rarely (we got sentry logging in place), we have a "TypeFailed to fetch (our-api-host.com)" Error. So when the call is being made, it immediately is failing, as if the api host does not exist or is not reachable.
Locally we are only able to reproduce this issue when we are shutting down the backend. We don't got any outages reported on the backend-side in production though. Has anyone experienced similar issues before?
We suspect that this might be related to the way Vercel handles edge functions and caching. As an optimistic workaround, we avoid calling the API directly from the client now and introduced an internal API route in NextJS that does the call to the API from the server side to avoid possible browser-plugins or anything on the client side interfering with the API call.
we got a weird issue in a project we don't know how to approach the debug, and we hope to get some new ideas from you. The Setup is a NextJS-Frontend hosted on Vercel, the Backend is a Symfony PHP Backend hosted on AWS. The Backend provides a pretty standard REST API, which in 95% we call via server-actions.
In one special case, we rely on direct calls from client to API directly, because we do not want to trigger any rerenderings of server-components whatsoever, and making requests with server-actions always produces these kind of sideeffects.
Most of the times this works without issues, but very rarely (we got sentry logging in place), we have a "TypeFailed to fetch (our-api-host.com)" Error. So when the call is being made, it immediately is failing, as if the api host does not exist or is not reachable.
Locally we are only able to reproduce this issue when we are shutting down the backend. We don't got any outages reported on the backend-side in production though. Has anyone experienced similar issues before?
We suspect that this might be related to the way Vercel handles edge functions and caching. As an optimistic workaround, we avoid calling the API directly from the client now and introduced an internal API route in NextJS that does the call to the API from the server side to avoid possible browser-plugins or anything on the client side interfering with the API call.