Awaiting a promise and adding a ntfy client error
This commit is contained in:
parent
bd634f9742
commit
36fc5d3745
2 changed files with 16 additions and 8 deletions
|
|
@ -2,6 +2,7 @@ import { Inject, Injectable } from '@nestjs/common'
|
||||||
import { ConfigService } from '@nestjs/config'
|
import { ConfigService } from '@nestjs/config'
|
||||||
import { Axios } from 'axios'
|
import { Axios } from 'axios'
|
||||||
|
|
||||||
|
import { LoggerService } from '../logger/service.logger'
|
||||||
import { MessageConfig } from './types'
|
import { MessageConfig } from './types'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|
@ -11,6 +12,9 @@ export class NtfyClient {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(ConfigService)
|
@Inject(ConfigService)
|
||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
|
|
||||||
|
@Inject(LoggerService)
|
||||||
|
private readonly loggerService: LoggerService,
|
||||||
) {
|
) {
|
||||||
const host = this.configService.getOrThrow<string>('NTFY_HOST')
|
const host = this.configService.getOrThrow<string>('NTFY_HOST')
|
||||||
this.topic = this.configService.getOrThrow<string>('NTFY_TOPIC')
|
this.topic = this.configService.getOrThrow<string>('NTFY_TOPIC')
|
||||||
|
|
@ -25,12 +29,16 @@ export class NtfyClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
async publish(message: Omit<MessageConfig, 'topic'>) {
|
async publish(message: Omit<MessageConfig, 'topic'>) {
|
||||||
return await this.httpClient.post(
|
try {
|
||||||
'/',
|
await this.httpClient.post(
|
||||||
JSON.stringify({
|
'/',
|
||||||
topic: this.topic,
|
JSON.stringify({
|
||||||
...message,
|
topic: this.topic,
|
||||||
}),
|
...message,
|
||||||
)
|
}),
|
||||||
|
)
|
||||||
|
} catch (error: unknown) {
|
||||||
|
this.loggerService.error('ntfy client failed', { error })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ export class ReservationsWorker {
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
this.loggerService.error('Error while performing reservation', error)
|
this.loggerService.error('Error while performing reservation', error)
|
||||||
this.ntfyProvider.sendErrorPerformingReservationNotification(
|
await this.ntfyProvider.sendErrorPerformingReservationNotification(
|
||||||
reservation.id,
|
reservation.id,
|
||||||
reservation.dateRangeStart,
|
reservation.dateRangeStart,
|
||||||
reservation.dateRangeEnd,
|
reservation.dateRangeEnd,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue