fix(telemetry): handle all promise rejections in ClearcutLogger (#1557)

Co-authored-by: Scott Densmore <scottdensmore@mac.com>
This commit is contained in:
zhiyue 2025-06-26 04:14:44 +08:00 committed by GitHub
parent 31f32421a3
commit b0cf9bcece
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 7 deletions

View File

@ -120,7 +120,8 @@ export class ClearcutLogger {
reject(e); reject(e);
}); });
req.end(body); req.end(body);
}).then((buf: Buffer) => { })
.then((buf: Buffer) => {
try { try {
this.last_flush_time = Date.now(); this.last_flush_time = Date.now();
return this.decodeLogResponse(buf) || {}; return this.decodeLogResponse(buf) || {};
@ -128,6 +129,12 @@ export class ClearcutLogger {
console.error('Error flushing log events:', error); console.error('Error flushing log events:', error);
return {}; return {};
} }
})
.catch((error: unknown) => {
// Handle all errors to prevent unhandled promise rejections
console.error('Error flushing log events:', error);
// Return empty response to maintain the Promise<LogResponse> contract
return {};
}); });
} }