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