mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-27 08:18:08 +03:00
19 lines
449 B
TypeScript
19 lines
449 B
TypeScript
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
|
|
}
|