Skip to content

Commit 88f11db

Browse files
committed
fix: Do not log stack-trace for soft-fail
1 parent 8c217dc commit 88f11db

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/actor/server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ export function createExpressApp(
3030
// Server errors (>= 500) - log as exception
3131
log.exception(error instanceof Error ? error : new Error(String(error)), 'Error in request', { logMessage, statusCode });
3232
} else {
33-
// Client errors (< 500) - log as softFail
34-
log.softFail('Error in request', { logMessage, error, statusCode });
33+
// Client errors (< 500) - log as softFail without stack trace
34+
const errorMessage = error instanceof Error ? error.message : String(error);
35+
log.softFail('Error in request', { logMessage, error: errorMessage, statusCode });
3536
}
3637
if (!res.headersSent) {
3738
res.status(statusCode).json({

src/utils/logging.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ export function getHttpStatusCode(error: unknown): number | undefined {
3939
*/
4040
export function logHttpError<T extends object>(error: unknown, message: string, data?: T): void {
4141
const statusCode = getHttpStatusCode(error);
42+
const errorMessage = error instanceof Error ? error.message : String(error);
4243

4344
if (statusCode !== undefined && statusCode < 500) {
44-
// Client errors (< 500) - log as softFail
45-
log.softFail(message, { error, statusCode, ...data });
45+
// Client errors (< 500) - log as softFail without stack trace
46+
log.softFail(message, { error: errorMessage, statusCode, ...data });
4647
} else if (statusCode !== undefined && statusCode >= 500) {
47-
// Server errors (>= 500) - log as exception
48+
// Server errors (>= 500) - log as exception with full error (includes stack trace)
4849
const errorObj = error instanceof Error ? error : new Error(String(error));
4950
log.exception(errorObj, message, { statusCode, ...data });
5051
} else {

0 commit comments

Comments
 (0)