fix: one Sentry issue per kind of API error; the expected 410 of a resumed upload is silent (Sentry 12/11)
Every failed API call landed in one issue titled Object.apiError; each now has its own fingerprint and title from status, path and message, with ids and file names normalized. The 410 of a recovered cart's expired upload was already handled (the file goes up again from the stored copy); the probe no longer reports it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -37,7 +37,7 @@
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
function clearDraft() { forgetDraft(); actions.replaceChildren(); }
|
||||
const api = async (path, body) => {
|
||||
const api = async (path, body, options = {}) => {
|
||||
const response = await fetch('/api'+path, {
|
||||
credentials: 'same-origin', headers: {'Content-Type':'application/json'},
|
||||
...(body === undefined ? {} : {method:'POST', body:JSON.stringify(body)})
|
||||
@@ -55,7 +55,10 @@
|
||||
const error=new Error(text);error.status=response.status;
|
||||
const retry=response.headers.get('Retry-After');
|
||||
if(retry!=null)error.retryAfter=retry;
|
||||
window.dtfObservability?.apiError?.(path,response.status,error.message,data.detail);
|
||||
// A status the caller expects (a resumed upload that expired) is handled
|
||||
// there, not reported.
|
||||
if(!(options.expected||[]).includes(response.status))
|
||||
window.dtfObservability?.apiError?.(path,response.status,error.message,data.detail);
|
||||
throw error;
|
||||
}
|
||||
return data;
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
(function () {
|
||||
const EMAIL = /[^\s@]+@[^\s@]+\.[A-Za-z]{2,}/g;
|
||||
const DOCUMENT = /(?<!\d)(?:\d{2}\.?\d{3}\.?\d{3}\/?\d{4}-?\d{2}|\d{3}\.?\d{3}\.?\d{3}-?\d{2})(?!\d)/g;
|
||||
// What changes from one API error to the next of the same kind: the ids of
|
||||
// the files, quotes and orders, the numbers and the file names.
|
||||
const UUID = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;
|
||||
const FILE_NAME = /[^\s"'<>:,;()[\]{}]+\.(?:png|jpe?g|pdf|tiff?|psd|psb|ai|cdr|webp|zip)\b/gi;
|
||||
const NUMBER = /\d+/g;
|
||||
const SENSITIVE_PARAM = /token|signature|x-amz/i;
|
||||
const SENSITIVE_HEADER = /^(cookie|authorization|x-.*token.*)$/i;
|
||||
const REDACTED = '[removido]';
|
||||
@@ -104,13 +109,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
const normalizedPath = value => clean(String(value == null ? '' : value)
|
||||
.replace(UUID, ':id').replace(NUMBER, ':id'));
|
||||
const normalizedMessage = value => clean(String(value == null ? '' : value)
|
||||
.replace(UUID, ':id').replace(FILE_NAME, ':arquivo').replace(NUMBER, ':id'));
|
||||
|
||||
function apiError(path, status, message, detail) {
|
||||
if (!started || status === 401 || typeof Sentry === 'undefined') return;
|
||||
try {
|
||||
// One issue per kind of API error: without this Sentry groups them all
|
||||
// by apiError and DTF-WEB-1 mixes a 422 for 66 files with a 422 for
|
||||
// 96 DPI. The title names the same kind as the fingerprint.
|
||||
const kindPath = normalizedPath(path);
|
||||
const kindMessage = normalizedMessage(message);
|
||||
const extra = {path, status, page: location.pathname};
|
||||
if (status === 422 && detail) extra.detail = detail;
|
||||
Sentry.captureMessage(clean('API ' + status + ' ' + path + ': ' + (message || '')),
|
||||
{level: 'error', tags: {app}, extra});
|
||||
Sentry.captureMessage('API ' + status + ' ' + kindPath + ': ' + kindMessage,
|
||||
{level: 'error', tags: {app}, extra,
|
||||
fingerprint: ['api-error', String(status), kindPath, kindMessage]});
|
||||
} catch (error) {
|
||||
// Reporting an error must never break the page.
|
||||
}
|
||||
|
||||
@@ -23,11 +23,12 @@ window.dtfUpload = async (file, {api, prefix='/uploads', startPath=prefix, progr
|
||||
};
|
||||
let id=resume?localStorage.getItem(key):null,state;
|
||||
if(id){
|
||||
try{state=await api(prefix+'/'+id);}
|
||||
try{state=await api(prefix+'/'+id,undefined,{expected:[403,404,410]});}
|
||||
catch(error){
|
||||
// The id was started under another session (a sign-in changes the scope):
|
||||
// the new session does not own it, so this file starts again as a new
|
||||
// upload. A 403/404/410 must never keep the retry on the old id.
|
||||
// The id is only a hint from the last visit. When the upload expired or
|
||||
// was started under another session (a sign-in changes the scope), this
|
||||
// file starts again as a new upload, silently, and its id is replaced.
|
||||
// These refusals are expected here and never reach Sentry.
|
||||
if(![403,404,410].includes(error.status))throw error;
|
||||
id=null;
|
||||
if(resume)localStorage.removeItem(key);
|
||||
|
||||
Reference in New Issue
Block a user