nestjs-telegraf/lib/decorators/TelegramCatch.ts
2019-02-28 10:29:26 +02:00

19 lines
470 B
TypeScript

import { Type } from '@nestjs/common'
import { TelegramErrorHandler } from '../interfaces/TelegramErrorHandler'
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
}