fengmk2
2025-02-13 02:20:02 +00:00
parent 9a17422d36
commit 0ce4cc8609
6 changed files with 48 additions and 16 deletions

View File

@@ -136,7 +136,7 @@ export class UserFriendlyError extends Error {
].join('\n');
}
log(context: string) {
log(context: string, debugInfo?: object) {
// ignore all user behavior error log
if (
this.type !== 'internal_server_error' &&
@@ -148,11 +148,15 @@ export class UserFriendlyError extends Error {
const logger = new Logger(context);
const fn = this.status >= 500 ? logger.error : logger.log;
fn.call(
logger,
this.name,
this.cause ? ((this.cause as any).stack ?? this.cause) : this.stack
);
let message = this.name;
if (debugInfo) {
message += ` (${JSON.stringify(debugInfo)})`;
}
let stack = this.stack ?? '';
if (this.cause) {
stack += `\n\nCaused by:\n\n${(this.cause as any).stack ?? this.cause}`;
}
fn.call(logger, message, stack);
}
}