Note: This does not occur in the development (npm run dev) environment. The development version will refresh as intended without the error.
I have an Electron-Vite app in deployment that uses a cronjob to fetch data from the server every morning and refresh the frontend. Every morning the production version returns the same error when the cronjob is supposed to execute:
Failed to load resource: net::ERR_INTERNET_DISCONNECTED
Despite having retry logic, nothing gets fetched and the page data remains stale until a user manually hits the refresh button, at which point everything refreshes as intended.
export const fetchWithRetry = async (url, options = {}, maxRetries = 3, delay = 5000) => {
for (let i = 0; i < maxRetries; i++) {
try {
const response = await axios(url, options);
return response;
} catch (error) {
console.error(`Attempt ${i + 1} failed:`, error.message);
if (error.response) {
console.error("Response data:", error.response.data);
console.error("Response status:", error.response.status);
} else if (error.request) {
console.error("No response received:", error.request);
} else {
console.error("Error setting up request:", error.message);
}
if (i === maxRetries - 1) {
throw error; // Rethrow the error after all retries have failed
}
await new Promise((resolve) => setTimeout(resolve, delay));
}
}
};
Here are my electron window settings:
const mainWindow = new BrowserWindow({
width: 1600,
height: 800,
show: false,
autoHideMenuBar: false,
...(process.platform === "linux" ? { icon } : {}),
webPreferences: {
preload: join(__dirname, "../preload/index.js"),
sandbox: false,
webSecurity: false,
nodeIntegration: true,
contextIsolation: false,
},
});