I'm trying to understand how to pass a database connection to an Exception filter. We log exceptions to our SQL database, so besides logging to console I have to insert the errors in a table.
What i did was write an RpcExceptionFilter, in the constructor I'm using a Logger and a DataSource. When I register the filter I do it in main.ts as:
const logger = app.get(Logger);
const ds = // how do I do this?
app.useGlobalFilters(
new HttpExceptionFilter(logger, ds),
new MyRPCExceptionFilter(logger, ds),
);
for other services in my app I just inject it:
constructor(
private readonly logger: Logger,
@InjectDataSource('datasourcename')
private readonly dataSource: DataSource,
) {}
but I can't do this here as I'm manually instantiating with new. What's the correct way to do this?