-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(api): add unhandled exception logger
- Loading branch information
Johan Book
authored and
Johan Book
committed
Jul 26, 2023
1 parent
671eead
commit 6a09178
Showing
2 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
services/api/src/core/logging/unhandled-exception.logger.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { UnhandledExceptionBus } from "@nestjs/cqrs"; | ||
|
||
import { Logger } from "./domain/services/logger.service"; | ||
|
||
@Injectable() | ||
export class UnhandledExceptionLogger { | ||
private logger = new Logger(UnhandledExceptionLogger.name); | ||
|
||
constructor(private readonly unhandledExceptionBus: UnhandledExceptionBus) { | ||
this.unhandledExceptionBus.subscribe((exceptionInfo) => { | ||
this.logger.error({ | ||
cause: exceptionInfo.cause, | ||
error: exceptionInfo.exception, | ||
msg: `Encountered unhandled exception ${exceptionInfo.exception.message}`, | ||
}); | ||
}); | ||
} | ||
} |