You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a static site on Vercel that makes a number of fetch requests to a Strapi backend on build. It occasionally throws this error.
at async file:///vercel/path0/dist/chunks/prerender_z0pSUssE.mjs:614:21
at async Object.render (file:///vercel/path0/dist/chunks/astro_4VOd5ehm.mjs:1572:7)
at async Object.renderToFinalDestination (file:///vercel/path0/dist/chunks/astro_4VOd5ehm.mjs:866:7)
at async renderChild (file:///vercel/path0/dist/chunks/astro_4VOd5ehm.mjs:1059:5)
Caused by:
other side closed
at TLSSocket.onSocketEnd (node:internal/deps/undici/undici:7998:26)
at endReadableNT (node:internal/streams/readable:1368:12)
Error: Command "npm run build" exited with 1
It only happens occasionally and if I reploy a few times it works eventually, so I'm guessing it's not a code error. The fetch code is.
interface Props {
endpoint: string;
query?: string;
wrappedByKey?: string;
wrappedByList?: boolean;
}
/**
* Fetches data from the Strapi API
* @param endpoint - The endpoint to fetch from
* @param query - The query parameters to add to the URL
* @param wrappedByKey - The key to unwrap the response from
* @param wrappedByList - If the response is a list, unwrap it
* @returns
*/
export default async function fetchApi<T>({
endpoint,
query,
wrappedByKey,
wrappedByList,
}: Props): Promise<T> {
try {
if (endpoint.startsWith('/')) {
endpoint = endpoint.slice(1);
}
const url = new URL(`${import.meta.env.STRAPI_URL}/api/${endpoint}`);
const queryString = query ? `?${query}` : '';
const urlWithQuery = `${url.toString()}${queryString}`;
const res = await fetch(urlWithQuery, {
method: "GET",
headers: {
Authorization: `Bearer ${import.meta.env.STRAPI_KEY}`,
"Content-Type": "application/json",
},
});
if (!res.ok) {
throw new Error(`HTTP error! Status: ${res.status}`);
}
let data = await res.json();
if (wrappedByKey) {
data = data[wrappedByKey];
}
if (wrappedByList) {
data = data[0];
}
return data as T;
} catch (error) {
// Handle errors here
console.error("Error fetching data:", error);
throw error; // Rethrow the error
}
}
The text was updated successfully, but these errors were encountered:
Duplicate of #1923 (and others). But if this happens when you're deploying the server probably is just forcefully closing the connection, which isn't an issue related to undici.
I have a static site on Vercel that makes a number of fetch requests to a Strapi backend on build. It occasionally throws this error.
It only happens occasionally and if I reploy a few times it works eventually, so I'm guessing it's not a code error. The fetch code is.
The text was updated successfully, but these errors were encountered: