Skip to content

Commit 8e9c9c7

Browse files
leomp12claude
andcommitted
fix(tiny-erp): Fix product import when image uploads fail
Product creation now continues even when image processing fails, with improved error logging and timeouts for better debugging. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 6091777 commit 8e9c9c7

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

packages/apps/tiny-erp/src/integration/parsers/product-from-tiny.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const tryImageUpload = async (originImgUrl: string, product: Products) => {
3131
try {
3232
const { data, headers } = await axios.get(originImgUrl, {
3333
responseType: 'arraybuffer',
34+
timeout: 10000,
3435
});
3536
const formData = new FormData();
3637
formData.append('file', new Blob(data), originImgUrl.replace(/.*\/([^/]+)$/, '$1'));
@@ -45,6 +46,7 @@ const tryImageUpload = async (originImgUrl: string, product: Products) => {
4546
'X-My-ID': authenticationId,
4647
'X-Access-Token': ecomAccessToken,
4748
},
49+
timeout: 35000,
4850
});
4951
if (picture) {
5052
Object.keys(picture).forEach((imgSize) => {
@@ -297,20 +299,34 @@ export default (
297299
}));
298300
}
299301
});
300-
Promise.all(promises).then((images) => {
302+
Promise.allSettled(promises).then((results) => {
303+
const images = results.map((result, index) => {
304+
if (result.status === 'rejected') {
305+
logger.warn('Image upload promise rejected', {
306+
index,
307+
reason: result.reason?.message || result.reason,
308+
productSku: product.sku,
309+
});
310+
return null;
311+
}
312+
return result.value;
313+
}).filter(Boolean);
301314
if (Array.isArray(product.variations) && product.variations.length) {
302315
product.variations.forEach((variation) => {
303316
if (typeof variation.picture_id === 'number') {
304317
const variationImage = images[variation.picture_id];
305-
if (variationImage._id) {
318+
if (variationImage?._id) {
306319
variation.picture_id = variationImage._id;
307320
} else {
308321
delete variation.picture_id;
309322
}
310323
}
311324
});
312325
}
313-
return resolve(product);
326+
resolve(product);
327+
}).catch((err) => {
328+
logger.error(err);
329+
resolve(product);
314330
});
315331
return;
316332
}

0 commit comments

Comments
 (0)