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:
Cauê Faleiros
2026-11-12 10:09:20 -03:00
parent d3918e83dc
commit 6896e6a161
5 changed files with 79 additions and 8 deletions

View File

@@ -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.
}