@@ -199,16 +199,24 @@ jobs:
199199
200200 let activeToken = tokens[0];
201201 async function mutateBatch(mutations, dataset = "dev") {
202- for (let attempt = 0; attempt < 5 ; attempt++) {
202+ for (let attempt = 0; attempt < 6 ; attempt++) {
203203 const token = activeToken || tokens[attempt % tokens.length];
204- const res = await fetch(`https://${projectId}.api.sanity.io/v2021-06-07/data/mutate/${dataset}?visibility=sync&autoGenerateArrayKeys=true`, {
205- method: "POST",
206- headers: {
207- Authorization: `Bearer ${token}`,
208- "Content-Type": "application/json",
209- },
210- body: JSON.stringify({ mutations }),
211- });
204+ let res;
205+ try {
206+ res = await fetch(`https://${projectId}.api.sanity.io/v2021-06-07/data/mutate/${dataset}?visibility=sync&autoGenerateArrayKeys=true`, {
207+ method: "POST",
208+ headers: {
209+ Authorization: `Bearer ${token}`,
210+ "Content-Type": "application/json",
211+ },
212+ body: JSON.stringify({ mutations }),
213+ });
214+ } catch (netErr) {
215+ const delay = 1000 * Math.pow(2, attempt);
216+ console.warn(`Network error (${netErr.message}), retrying in ${delay}ms...`);
217+ await new Promise((r) => setTimeout(r, delay));
218+ continue;
219+ }
212220 if (res.ok) {
213221 activeToken = token;
214222 return;
@@ -226,15 +234,15 @@ jobs:
226234 }
227235 throw new Error(`Mutate batch (${dataset}) failed: HTTP ${res.status}: ${errText}`);
228236 }
229- throw new Error(`Mutate batch (${dataset}) failed after 5 retries.`);
237+ throw new Error(`Mutate batch (${dataset}) failed after 6 retries.`);
230238 }
231239
232240 async function sendChunked(items, label, op = "createOrReplace") {
233241 let batch = [];
234242 let batchBytes = 0;
235243 let sent = 0;
236- const MAX_ITEMS = 200 ;
237- const MAX_BYTES = 2500000 ;
244+ const MAX_ITEMS = 100 ;
245+ const MAX_BYTES = 1500000 ;
238246
239247 for (const item of items) {
240248 const mutation = op === "raw" ? item : { [op]: item };
0 commit comments