Discord | |
---|---|
![]() |
not implemented yet |
Watchman is an error cather for Nest framework.
$ npm install @dev-codenix/nest-watchman --save
// all-exception-filter.ts
constructor(private watchManService: WatchmanService) {
super();
}
public catch(exception: IException, host: ArgumentsHost): void {
this.watchManService.watch(exception,{
host,
metaData:{},
trackUUID:'uuid'
});
...
}
host
host
object exist in exception filter. we get the expressrequest
andresponse
from this object
metaData
- you can pass anything in this field, but it doesn't any effect on default message. you can access to this data in custom strategy through
super.metaData
- you can pass anything in this field, but it doesn't any effect on default message. you can access to this data in custom strategy through
trackUUID
- if you want to have an uuid to track your errors. note that you can pass uuid in your exception object we have this interface for this purpose
IException
- if you want to have an uuid to track your errors. note that you can pass uuid in your exception object we have this interface for this purpose
this.watchManService.watch(exception,{
metaData:{},
trackUUID:'uuid'
});
you don't need to pass host
here
strategy
- you can use the default strategies that provided by us, it has default message structure, and you don't have to do anything about it, or you can use a custom strategy
catchOnlyInternalExceptions
- if you pass
true
Watchman will catch only the internal server errors.default=false
- if you pass
strategyConfig
- it will change base on your strategy
// app.module.ts
@Module({
imports: [
WatchmanModule.forRoot({
strategy: DiscordBaseStrategy,
catchOnlyInternalExceptions: true,
strategyConfig: {
webHookUrl: 'https://discord.com/api/webhooks/id/token',
mentionList: ['everyone'],
},
}),
],
})
// app.module.ts
@Module({
imports: [
WatchmanModule.forRootAsync({
imports:[AppConfigModule],
useFactory: (configService: AppConfigService) => {
return {
strategy: DiscordBaseStrategy,
catchOnlyInternalExceptions: true,
strategyConfig: {
webHookUrl: configService.WATCHMAN_WEBHOOK,
mentionList: ['everyone'],
},
};
},
inject: [AppConfigService],
}),
],
})
// app.module.ts
@Module({
imports: [
WatchmanModule.forRootAsync({
imports:[DiscordConfigModule],
useClass: DiscordConfigService
}),
],
})
// discord.config.service.ts
@Injectable()
export class DiscordConfigService implements WatchmanModuleFactory{
constructor(private configService: ConfigService) {}
get WATCHMAN_WEBHOOK(): string {
return this.configService.get<string>('App.WATCHMAN_WEBHOOK');
}
createWatchmanModuleOptions(): Promise<WatchmanModuleOptions> | WatchmanModuleOptions {
return {
strategy: DiscordBaseStrategy,
catchOnlyInternalExceptions: false,
strategyConfig: {
webHookUrl: this.WATCHMAN_WEBHOOK,
mentionList: ['everyone'],
}
}
}
}
you can implement your config service class from WatchmanModuleFactory
interface
// discord.strategy.ts
@Injectable()
export class DiscordStrategy extends DiscordBaseStrategy {
constructor(private configService: AppConfigService) {
super({
webHookUrl: configService.WATCHMAN_WEBHOOK,
mentionList: ["here"]
});
}
withMetaDataMessageFormat(): IDiscordBody {
return super.withMetaDataMessageFormat();
}
simpleMessageFormat(): IDiscordBody {
return super.simpleMessageFormat();
}
}
these are the configs that you should pass in strategyConfig
property or in custom strategy's constructor
{
webHookUrl: configService.WATCHMAN_WEBHOOK,
mentionList: ['everyone']
}
webHookUrl
- discord web hook url. you can find it here
mentionList
- list of persons that you want to mention in the discord channel. example
here, everyone
- note that don't use @ in the mentions.
- to mention a person you need to pass user id or role id. Where can I find my User OR Role ID
- list of persons that you want to mention in the discord channel. example
in development process
in development process
in development process
- Author - Em Daneshjoo
Watchman is MIT licensed.