mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-28 00:28:10 +03:00
32 lines
791 B
Markdown
32 lines
791 B
Markdown
---
|
|
id: error-handling
|
|
title: Error handling
|
|
sidebar_label: Error handling
|
|
slug: /error-handling
|
|
---
|
|
|
|
By default, `nestjs-telegraf` catches all errors using the `Logger` built into NestJS.
|
|
|
|
Use can disable global errors catch with `disableGlobalCatch`:
|
|
```typescript
|
|
TelegrafModule.forRoot({
|
|
disableGlobalCatch: true,
|
|
}),
|
|
```
|
|
|
|
After that you can override errors handling with bot instance `catch` function.
|
|
|
|
```typescript
|
|
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);
|
|
});
|
|
}
|
|
}
|
|
```
|