Skip to content

Commit b09178a

Browse files
committed
properly log http server errors
1 parent 16b344d commit b09178a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/core/src/v3/serverOnly/httpServer.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export class HttpServer {
201201
);
202202

203203
if (error) {
204-
logger.error("Route handler error", { error });
204+
logger.error("Route handler error", { error: this.formatError(error) });
205205
return reply.empty(500);
206206
}
207207

@@ -210,7 +210,7 @@ export class HttpServer {
210210
return;
211211
}
212212
} catch (error) {
213-
logger.error("Failed to handle request", { error });
213+
logger.error("Failed to handle request", { error: this.formatError(error) });
214214
return reply.empty(500);
215215
} finally {
216216
this.collectMetrics(req, res, startTime);
@@ -364,4 +364,16 @@ export class HttpServer {
364364

365365
return null;
366366
}
367+
368+
private formatError(error: unknown): string | Record<string, string | undefined> {
369+
if (error instanceof Error) {
370+
return {
371+
name: error.name,
372+
message: error.message,
373+
stack: error.stack,
374+
};
375+
}
376+
377+
return String(error);
378+
}
367379
}

0 commit comments

Comments
 (0)