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 { Axios } from 'axios'
|
||||
|
||||
import { LoggerService } from '../logger/service.logger'
|
||||
import { MessageConfig } from './types'
|
||||
|
||||
@Injectable()
|
||||
|
|
@ -11,6 +12,9 @@ export class NtfyClient {
|
|||
constructor(
|
||||
@Inject(ConfigService)
|
||||
private readonly configService: ConfigService,
|
||||
|
||||
@Inject(LoggerService)
|
||||
private readonly loggerService: LoggerService,
|
||||
) {
|
||||
const host = this.configService.getOrThrow<string>('NTFY_HOST')
|
||||
this.topic = this.configService.getOrThrow<string>('NTFY_TOPIC')
|
||||
|
|
@ -25,12 +29,16 @@ export class NtfyClient {
|
|||
}
|
||||
|
||||
async publish(message: Omit<MessageConfig, 'topic'>) {
|
||||
return await this.httpClient.post(
|
||||
'/',
|
||||
JSON.stringify({
|
||||
topic: this.topic,
|
||||
...message,
|
||||
}),
|
||||
)
|
||||
try {
|
||||
await this.httpClient.post(
|
||||
'/',
|
||||
JSON.stringify({
|
||||
topic: this.topic,
|
||||
...message,
|
||||
}),
|
||||
)
|
||||
} catch (error: unknown) {
|
||||
this.loggerService.error('ntfy client failed', { error })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ export class ReservationsWorker {
|
|||
}
|
||||
default:
|
||||
this.loggerService.error('Error while performing reservation', error)
|
||||
this.ntfyProvider.sendErrorPerformingReservationNotification(
|
||||
await this.ntfyProvider.sendErrorPerformingReservationNotification(
|
||||
reservation.id,
|
||||
reservation.dateRangeStart,
|
||||
reservation.dateRangeEnd,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue