nestjs-telegraf/lib/decorators/telegram-catch.decorator.ts

19 lines
449 B
TypeScript
Raw Normal View History

2019-02-28 11:29:26 +03:00
import { Type } from '@nestjs/common'
2020-01-12 02:41:27 +03:00
import { TelegramErrorHandler } from '../interfaces'
2019-02-28 11:29:26 +03:00
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
}