How to catch NestJS exceptions thrown in `forFeature` or `forRoot`?

Viewed 449

I setuped configuration validation as described in documentation of NestJS: https://docs.nestjs.com/techniques/configuration#schema-validation

Validation works as expected, but when my .env file is not valid, I am getting plain error, for example:

Error: Config validation error: "FOO_BAR" is required at Function.forRoot (<PATH>\@nestjs\config\dist\config.module.js:44:27)

This error is not thrown by Nest so approach with globalFilter what can catch every Nest error not work: https://docs.nestjs.com/websockets/exception-filters#exception-filters

How to catch this error to be able to format it?

EDIT: This is more general question: How to catch errors thrown inside forRoot, forFeature in NestJS?

0 Answers
Related