From 69e360b940c8463bb1247bace43ea1f056b779d9 Mon Sep 17 00:00:00 2001 From: shats Date: Tue, 24 Feb 2026 12:41:44 +0700 Subject: [PATCH] feat(api): implement logging for canceled API requests to improve error handling and debugging --- .cursor/debug-378b5f.log | 2 +- frontend/src/lib/api.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.cursor/debug-378b5f.log b/.cursor/debug-378b5f.log index 75b536d..43e7d57 100644 --- a/.cursor/debug-378b5f.log +++ b/.cursor/debug-378b5f.log @@ -1 +1 @@ -{\ +{"sessionId":"378b5f","runId":"baseline","hypothesisId":"H1_H2","location":"frontend/src/lib/api.js:request","message":"API request started","data":{"method":"GET","url":"/alerts"},"timestamp":1771911695277} diff --git a/frontend/src/lib/api.js b/frontend/src/lib/api.js index 7aed1c6..81e6203 100644 --- a/frontend/src/lib/api.js +++ b/frontend/src/lib/api.js @@ -64,6 +64,14 @@ api.interceptors.response.use( return response; }, async (error) => { + const isCanceled = error?.code === 'ERR_CANCELED' || error?.name === 'CanceledError' || error?.name === 'AbortError'; + if (isCanceled) { + // #region agent log + fetch('http://192.168.10.2:7343/ingest/aa002dd6-6968-4a35-b09d-f05302d83266',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'378b5f'},body:JSON.stringify({sessionId:'378b5f',runId:'post-fix',hypothesisId:'H1_H2',location:'frontend/src/lib/api.js:retry-skip-canceled',message:'Skip retry for canceled request',data:{method:String(error?.config?.method||'get').toUpperCase(),url:String(error?.config?.url||''),code:String(error?.code||'')},timestamp:Date.now()})}).catch(()=>{}); + // #endregion + return Promise.reject(error); + } + const config = error?.config || {}; const method = String(config.method || 'get').toUpperCase(); @@ -107,6 +115,14 @@ api.interceptors.response.use( api.interceptors.response.use( (res) => res, (err) => { + const isCanceled = err?.code === 'ERR_CANCELED' || err?.name === 'CanceledError' || err?.name === 'AbortError'; + if (isCanceled) { + // #region agent log + fetch('http://192.168.10.2:7343/ingest/aa002dd6-6968-4a35-b09d-f05302d83266',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'378b5f'},body:JSON.stringify({sessionId:'378b5f',runId:'post-fix',hypothesisId:'H1_H2',location:'frontend/src/lib/api.js:global-skip-canceled',message:'Skip global error handling for canceled request',data:{method:String(err?.config?.method||'get').toUpperCase(),url:String(err?.config?.url||''),code:String(err?.code||'')},timestamp:Date.now()})}).catch(()=>{}); + // #endregion + return Promise.reject(err); + } + // #region agent log fetch('http://192.168.10.2:7343/ingest/aa002dd6-6968-4a35-b09d-f05302d83266',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'378b5f'},body:JSON.stringify({sessionId:'378b5f',runId:'baseline',hypothesisId:'H1_H2',location:'frontend/src/lib/api.js:error',message:'API response error',data:{method:String(err?.config?.method||'get').toUpperCase(),url:String(err?.config?.url||''),status:Number(err?.response?.status||0),code:String(err?.response?.data?.code||err?.code||'')},timestamp:Date.now()})}).catch(()=>{}); // #endregion