mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-12-14 17:30:58 +03:00
refactor(): complex refactoring
This commit is contained in:
18
lib/decorators/telegram-catch.decorator.ts
Normal file
18
lib/decorators/telegram-catch.decorator.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Type } from '@nestjs/common'
|
||||
import { TelegramErrorHandler } from '../interfaces'
|
||||
|
||||
type Decorator = (error: any) => ClassDecorator
|
||||
|
||||
type HandlerDecorator = Decorator & {
|
||||
handlers?: Map<Error, Type<TelegramErrorHandler>>
|
||||
}
|
||||
|
||||
export const TelegramCatch: HandlerDecorator = error => target => {
|
||||
if (!TelegramCatch.handlers) {
|
||||
TelegramCatch.handlers = new Map()
|
||||
}
|
||||
|
||||
TelegramCatch.handlers.set(error, target as any)
|
||||
|
||||
return target
|
||||
}
|
||||
Reference in New Issue
Block a user