From 2f67fdc1238ef32a5f9ebefca966f1d47a5cc6bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Wed, 18 Nov 2026 09:29:23 -0300 Subject: [PATCH] fix: a Site upload that never reached the server tries once more, then says the connection is down (DTF-WEB-X) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A customer's POST /api/uploads failed with "Failed to fetch" before any part was sent (05:07 UTC): their network, not the Site. The upload now tries again three seconds later; if that fails too, the file shows "sem conexão com o servidor. Confira a internet e tente de novo" with the "Tentar de novo" button, and Sentry hears of it as before. Co-Authored-By: Claude Opus 5.5 (1M context) --- web/checkout.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/web/checkout.js b/web/checkout.js index b831c6b..fdb18b8 100644 --- a/web/checkout.js +++ b/web/checkout.js @@ -247,8 +247,22 @@ e={file, sent:0, done:false, failed:null, stop:new AbortController()}; e.promise=(async()=>{ const session=await ready; - return window.dtfUpload(file,{api,scope:session.cart_scope,progress:()=>{},signal:e.stop.signal, + const go=()=>window.dtfUpload(file,{api,scope:session.cart_scope,progress:()=>{},signal:e.stop.signal, onBytes:n=>{e.sent=n;pintaEnvio();}}); + // A request that never reached the server (the customer's network + // dropped, Sentry DTF-WEB-X) gets one more try a moment later; if + // that fails too, the customer reads that the connection is down. + try{return await go();} + catch(error){ + if(!(error instanceof TypeError))throw error; + await new Promise(r=>setTimeout(r,3000)); + if(e.stop.signal.aborted)throw new DOMException('Envio cancelado','AbortError'); + try{return await go();} + catch(again){ + if(again instanceof TypeError)throw new Error('sem conexão com o servidor. Confira a internet e tente de novo'); + throw again; + } + } })(); e.promise.then(()=>{e.done=true;if(window.dtfTimings)T.uploadEnd=performance.now();falhas.delete(k);pintaEnvio();}, error=>{envios.delete(k);if(error?.name!=='AbortError'){falhas.set(k,{file,error});