-
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.
Merge pull request #216 from johanbook/unexpected-exception-logger
Add logger for unexpected exceptions in comands and events
- Loading branch information
Showing
4 changed files
with
31 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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}`, | ||
}); | ||
}); | ||
} | ||
} |