Improve admin client error logging
TaxBaik CI/CD / build-and-deploy (push) Successful in 5m20s

This commit is contained in:
2026-07-08 01:54:16 +09:00
parent ecd40e7856
commit 30275c7952
@@ -46,6 +46,52 @@ window.taxbaikAdminSession = {
window.taxbaikAdminSession.postClientLog = postLog; window.taxbaikAdminSession.postClientLog = postLog;
if (!window._taxbaikConsoleErrorPatched) {
window._taxbaikConsoleErrorPatched = true;
const originalConsoleError = console.error.bind(console);
console.error = function (...args) {
try {
const text = args.map(arg => {
if (arg instanceof Error) {
return `${arg.message}\n${arg.stack || ''}`;
}
if (typeof arg === 'string') return arg;
try {
return JSON.stringify(arg);
} catch {
return String(arg);
}
}).join(' ');
if (text && !text.includes('taxbaikAdminSession.postClientLog') && !text.includes('client-logs')) {
postLog({
level: 'error',
source: 'console.error',
message: text.slice(0, 1000),
url: window.location.href,
route: window.location.pathname + window.location.search,
screen: window.taxbaikAdminSession.clientLogState.screen || '',
feature: window.taxbaikAdminSession.clientLogState.feature || '',
action: window.taxbaikAdminSession.clientLogState.action || '',
step: window.taxbaikAdminSession.clientLogState.step || '',
entity: window.taxbaikAdminSession.clientLogState.entity || '',
entityId: window.taxbaikAdminSession.clientLogState.entityId || '',
dataKey: window.taxbaikAdminSession.clientLogState.dataKey || '',
buildVersion: window.taxbaikAdminBuildVersion || '',
component: window.taxbaikAdminComponent || '',
viewportWidth: window.taxbaikAdminSession.getViewportWidth(),
userAgent: navigator.userAgent || '',
stack: args.find(arg => arg instanceof Error)?.stack || ''
});
}
} catch {
// Logging must never break the UI.
}
return originalConsoleError(...args);
};
}
window.addEventListener('error', function (event) { window.addEventListener('error', function (event) {
postLog({ postLog({
level: 'error', level: 'error',
@@ -90,6 +136,12 @@ window.taxbaikAdminSession = {
stack: reason?.stack || '' stack: reason?.stack || ''
}); });
}); });
window.addEventListener('load', function () {
window.taxbaikAdminSession.traceUiState('startup', 'window.load');
}, { once: true });
window.taxbaikAdminSession.traceUiState('startup', 'initErrorLogging attached');
}, },
setContext: function (screen, feature, action, step, entity, entityId, dataKey) { setContext: function (screen, feature, action, step, entity, entityId, dataKey) {