feat: every error shown in red reaches Sentry, also the ones the page handled itself
Some checks failed
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled
Some checks failed
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled
Until now only failed API calls and uncaught exceptions reached Sentry. An error the page caught and showed, like the folders' "A última tentativa falhou" Marcus photographed on 16/11, or an upload that failed on the Site, never did. Now every red message in the Kanban, the Site's checkout, the customer's account page and every failed upload is sent, one issue per kind of message; the same text an API error already sent, or a 401 / restart 503 it skips on purpose, is not sent twice. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -47,4 +47,19 @@ assert.notDeepEqual(
|
||||
apiError('/quotes/ba39b432-b0d1-4b1b-8971-09123e067067', 422, expired).options.fingerprint,
|
||||
apiError('/orders/ba39b432-b0d1-4b1b-8971-09123e067067', 422, expired).options.fingerprint);
|
||||
|
||||
// Every red message reaches Sentry, also one the page caught itself; the
|
||||
// same text an API error already sent (or deliberately skipped) is not doubled.
|
||||
captured = null;
|
||||
window.dtfObservability.uiError('Pastas automáticas: A última tentativa falhou: DTF-26-item-1.png bloqueado.', 'kanban');
|
||||
assert.ok(captured, 'uiError sends a caught error');
|
||||
assert.equal(captured.message, 'Aviso kanban: Pastas automáticas: A última tentativa falhou: :arquivo bloqueado.');
|
||||
assert.deepEqual(captured.options.fingerprint, ['ui-error', 'kanban', 'Pastas automáticas: A última tentativa falhou: :arquivo bloqueado.']);
|
||||
apiError('/orders', 409, 'Falta a foto da revisão.');
|
||||
captured = null;
|
||||
window.dtfObservability.uiError('Falta a foto da revisão.', 'kanban');
|
||||
assert.equal(captured, null, 'an API error shown in red is sent once');
|
||||
window.dtfObservability.apiError('/board', 503, 'O sistema está reiniciando.');
|
||||
window.dtfObservability.uiError('O sistema está reiniciando.', 'kanban');
|
||||
assert.equal(captured, null, 'a skipped restart 503 stays skipped');
|
||||
|
||||
console.log('observability web checks passed');
|
||||
|
||||
@@ -152,7 +152,10 @@
|
||||
// One message line under the steps. Its tone says what it is: a refusal or
|
||||
// a missing field is an error (red), a cart that changed a warning, a
|
||||
// created order a confirmation, the rest information.
|
||||
function message(text, tone='info') { status.textContent = text; status.dataset.tone = text ? tone : ''; }
|
||||
function message(text, tone='info') {
|
||||
status.textContent = text; status.dataset.tone = text ? tone : '';
|
||||
if (tone === 'error' && text) window.dtfObservability?.uiError?.(text, 'site');
|
||||
}
|
||||
function button(label, handler, into = actions, className = 'pagBtn') {
|
||||
const el = document.createElement('button');
|
||||
el.type = 'button';
|
||||
@@ -248,7 +251,8 @@
|
||||
onBytes:n=>{e.sent=n;pintaEnvio();}});
|
||||
})();
|
||||
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});pintaEnvio();});
|
||||
error=>{envios.delete(k);if(error?.name!=='AbortError'){falhas.set(k,{file,error});
|
||||
window.dtfObservability?.uiError?.('Envio de arquivo falhou: '+(error?.message||'erro no envio'),'site');}pintaEnvio();});
|
||||
envios.set(k,e);
|
||||
}
|
||||
return e.promise;
|
||||
|
||||
@@ -99,6 +99,7 @@ function button(text,fn,className='btn'){
|
||||
let sayTimer=null;
|
||||
function say(text,error=false,ms){
|
||||
clearTimeout(sayTimer);
|
||||
if(error&&text)window.dtfObservability?.uiError?.(text,'kanban');
|
||||
for(const id of ['status','login-status']){$(id).textContent=text||'';$(id).classList.toggle('error',!!error);}
|
||||
if(text)sayTimer=setTimeout(()=>say(''),ms??(error?8000:4000));
|
||||
}
|
||||
|
||||
@@ -114,7 +114,11 @@
|
||||
const normalizedMessage = value => clean(String(value == null ? '' : value)
|
||||
.replace(UUID, ':id').replace(FILE_NAME, ':arquivo').replace(NUMBER, ':id'));
|
||||
|
||||
// What apiError already sent, so the same text shown in red is not sent twice.
|
||||
const recent = new Map();
|
||||
function apiError(path, status, message, detail) {
|
||||
// Recorded first: a skipped 401 or restart 503 stays out of uiError too.
|
||||
recent.set(String(message), Date.now());
|
||||
if (!started || status === 401 || typeof Sentry === 'undefined') return;
|
||||
// A restart's few seconds without the database (app/app.py): not a bug.
|
||||
if (status === 503 && /reiniciando/.test(String(message))) return;
|
||||
@@ -134,5 +138,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
window.dtfObservability = {start, apiError, scrub};
|
||||
// Every error the page shows the user in red, also the ones it caught and
|
||||
// handled itself (a folder it could not write, an upload that failed): the
|
||||
// team sees them in Sentry before anyone sends a screenshot.
|
||||
function uiError(text, where) {
|
||||
if (!started || !text || typeof Sentry === 'undefined') return;
|
||||
const said = recent.get(String(text));
|
||||
if (said && Date.now() - said < 15000) return;
|
||||
try {
|
||||
const kind = normalizedMessage(text);
|
||||
Sentry.captureMessage('Aviso ' + (where || app) + ': ' + kind,
|
||||
{level: 'error', tags: {app, aviso: where || app}, extra: {page: location.pathname},
|
||||
fingerprint: ['ui-error', where || app, kind]});
|
||||
} catch (error) {
|
||||
// Reporting an error must never break the page.
|
||||
}
|
||||
}
|
||||
|
||||
window.dtfObservability = {start, apiError, uiError, scrub};
|
||||
})();
|
||||
|
||||
@@ -38,7 +38,8 @@ let scope,states={},environment='',conta=null;
|
||||
let filtro={status:'all',code:'',days:0,page:1};
|
||||
|
||||
async function api(path,body){const r=await fetch('/api'+path,{headers:{'Content-Type':'application/json'},...(body===undefined?{}:{method:'POST',body:JSON.stringify(body)})});const d=await r.json();if(!r.ok){const error=new Error(typeof d.detail==='string'?d.detail:'Confira os campos informados.');error.status=r.status;throw error;}return d;}
|
||||
const aviso=(text,erro)=>{$('message').textContent=text||'';$('message').classList.toggle('erro',!!erro);};
|
||||
const aviso=(text,erro)=>{$('message').textContent=text||'';$('message').classList.toggle('erro',!!erro);
|
||||
if(erro&&text)window.dtfObservability?.uiError?.(text,'conta');};
|
||||
function button(text,fn,className='bSec'){const b=node('button',text,className);b.type='button';b.onclick=async event=>{event?.stopPropagation?.();b.disabled=true;try{await fn();}catch(e){aviso(e.message,true);}finally{b.disabled=false;}};return b;}
|
||||
function forgetCheckout(){for(const k of ['dtf-quote','dtf-request-key','dtf-request-body'])localStorage.removeItem(k);}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user