chore(server): better internal error stack (#11009)

This commit is contained in:
forehalo
2025-03-19 16:41:56 +00:00
parent b3c6333694
commit b3a245f47a
4 changed files with 24 additions and 35 deletions
@@ -1,6 +1,8 @@
import { ConsoleLogger, Injectable, type LogLevel } from '@nestjs/common';
import { ClsServiceManager } from 'nestjs-cls';
import { UserFriendlyError } from '../error';
// DO NOT use this Logger directly
// Use it via this way: `private readonly logger = new Logger(MyService.name)`
@Injectable()
@@ -20,7 +22,14 @@ export class AFFiNELogger extends ConsoleLogger {
static formatStack(stackOrError?: Error | string | unknown) {
if (stackOrError instanceof Error) {
const err = stackOrError;
let err = stackOrError;
// most of the internal error are caught and created by `GlobalExceptionFilter`,
// and their error stack is helpless
if (err instanceof UserFriendlyError) {
return err.stacktrace;
}
let stack = err.stack ?? '';
if (err.cause instanceof Error && err.cause.stack) {
stack += `\n\nCaused by:\n\n${err.cause.stack}`;