We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relates to #1156
I find my app crashing whenever the bot throws. Is there a way to prevent this from happening?
The text was updated successfully, but these errors were encountered:
@llegoelkelo you can handle all unhandled Promise rejections (not only from this library) by adding listener for unhandledRejection events.
unhandledRejection
The easiest way is to add following code before await this.app.listen(port);:
await this.app.listen(port);
process.on('unhandledRejection', (reason) => { console.error(reason); });
If you prefer more robust way (e.g. sending logs or any other action in case of error) you can achieve that by two following steps:
import { Injectable, Logger } from '@nestjs/common'; @Injectable() export class UnhandledLogger { private readonly logger: Logger = new Logger(UnhandledLogger.name); constructor() { process.on('unhandledRejection', (reason) => { this.logger.error(reason); // here you can do anything else }); } }
providers: [ UnhandledLogger, { provide: APP_GUARD, useClass: AuthenticationGuard, }, ],
Second approach is more flexible because UnhandledLogger is simple NestJS Service so you can use IoC, DB connections and anything else.
UnhandledLogger
To test this solution you can simply run two instances of your NestJS application.
Sorry, something went wrong.
No branches or pull requests
Relates to #1156
I find my app crashing whenever the bot throws. Is there a way to prevent this from happening?
The text was updated successfully, but these errors were encountered: