fix(web): silence console for expected failures (CSRF, webhooks 5xx)
- csrf: no log when backend returns HTML (wrong server / not running) - webhookService: no log for 5xx on list webhooks - api client: no log for 5xx on /webhooks (main + queued request) Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
ee3225a75d
commit
ae4e184fad
3 changed files with 26 additions and 26 deletions
|
|
@ -1421,15 +1421,17 @@ apiClient.interceptors.response.use(
|
|||
return apiClient(originalRequest);
|
||||
})
|
||||
.catch((err) => {
|
||||
const errStatus = (err as { response?: { status?: number } })?.response?.status;
|
||||
const errAny = err as { response?: { status?: number }; code?: number };
|
||||
const errStatus = errAny?.response?.status ?? errAny?.code;
|
||||
const errUrl = originalRequest?.url ?? '';
|
||||
const isWebhooks5xx = errStatus && errStatus >= 500 && errUrl.includes('/webhooks');
|
||||
const logFn = isWebhooks5xx ? logger.debug : logger.error;
|
||||
logFn('[API] Queued request failed after refresh', {
|
||||
request_id: requestId,
|
||||
url: originalRequest?.url,
|
||||
error: err,
|
||||
});
|
||||
const isWebhooks5xx = errStatus != null && errStatus >= 500 && errUrl.includes('/webhooks');
|
||||
if (!isWebhooks5xx) {
|
||||
logger.error('[API] Queued request failed after refresh', {
|
||||
request_id: requestId,
|
||||
url: originalRequest?.url,
|
||||
error: err,
|
||||
});
|
||||
}
|
||||
return Promise.reject(err);
|
||||
});
|
||||
}
|
||||
|
|
@ -1951,21 +1953,22 @@ apiClient.interceptors.response.use(
|
|||
}
|
||||
|
||||
// FIX #18, #22: Utiliser logger structuré avec request_id pour corrélation
|
||||
// 5xx sur /webhooks = erreur backend, éviter le bruit console (DEBUG)
|
||||
// 5xx sur /webhooks = erreur backend, ne pas logger (éviter bruit console)
|
||||
const httpStatus = error.response?.status;
|
||||
const url = originalRequest?.url ?? '';
|
||||
const isWebhooks5xx = httpStatus && httpStatus >= 500 && url.includes('/webhooks');
|
||||
const logFn = isWebhooks5xx ? logger.debug : logger.error;
|
||||
logFn(`[API Error] ${apiError.message}`, {
|
||||
request_id: apiError.request_id || requestId,
|
||||
code: apiError.code,
|
||||
message: apiError.message,
|
||||
timestamp: apiError.timestamp,
|
||||
details: apiError.details,
|
||||
context: apiError.context,
|
||||
url: originalRequest?.url,
|
||||
method: originalRequest?.method,
|
||||
});
|
||||
if (!isWebhooks5xx) {
|
||||
logger.error(`[API Error] ${apiError.message}`, {
|
||||
request_id: apiError.request_id || requestId,
|
||||
code: apiError.code,
|
||||
message: apiError.message,
|
||||
timestamp: apiError.timestamp,
|
||||
details: apiError.details,
|
||||
context: apiError.context,
|
||||
url: originalRequest?.url,
|
||||
method: originalRequest?.method,
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.reject(apiError);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -31,9 +31,7 @@ class CSRFService {
|
|||
const msg = error instanceof Error ? error.message : String(error);
|
||||
const isWrongServer = msg.includes('HTML page instead of JSON');
|
||||
if (isWrongServer) {
|
||||
logger.debug('CSRF token unavailable (backend may not be running)', {
|
||||
hint: 'Ensure the Veza backend is running (see VITE_BACKEND_PORT in .env.local)',
|
||||
});
|
||||
// No log: backend not running or wrong server is expected in dev
|
||||
} else {
|
||||
logger.error('Failed to fetch CSRF token', { message: msg });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,11 +27,10 @@ export const webhookService = {
|
|||
const err = error as { response?: { status?: number }; code?: number };
|
||||
const status = err?.response?.status ?? err?.code;
|
||||
const is5xx = typeof status === 'number' && status >= 500;
|
||||
if (is5xx) {
|
||||
logger.debug('[Webhooks] Backend error listing webhooks (5xx)', { status });
|
||||
} else {
|
||||
if (!is5xx) {
|
||||
logger.error('[Webhooks] Failed to list webhooks', { error });
|
||||
}
|
||||
// 5xx: no log (backend error, avoid console noise)
|
||||
return [];
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue