nestjs-telegraf/website/docs/error-handling.md
2021-01-02 03:10:25 +03:00

791 B

id title sidebar_label slug
error-handling Error handling Error handling /error-handling

By default, nestjs-telegraf catches all errors using the Logger built into NestJS.

Use can disable global errors catch with disableGlobalCatch:

TelegrafModule.forRoot({
  disableGlobalCatch: true,  
}),

After that you can override errors handling with bot instance catch function.

import { Injectable } from '@nestjs/common';
import { InjectBot, TelegrafProvider, Context } from 'nestjs-telegraf';

@Injectable()
export class BotSettingsService {
  constructor(@InjectBot() private bot: TelegrafProvider<Context>) {
    this.bot.catch((err, ctx) => {
      console.log(`Ooops, encountered an error for ${ctx.updateType}`, err);
    });
  }
}