fix: a Site upload that never reached the server tries once more, then says the connection is down (DTF-WEB-X)
All checks were successful
Build and deploy / Validate source (push) Successful in 1m46s
Build and deploy / Integration suite on a real stack (push) Successful in 7m52s
Build and deploy / Secret scan and release gate (push) Successful in 10s
Build and deploy / Publish images (push) Successful in 1m56s

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) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-18 09:29:23 -03:00
parent d76288c335
commit 2f67fdc123

View File

@@ -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});