Awaiting a promise and adding a ntfy client error

This commit is contained in:
Collin Duncan 2023-09-13 21:29:45 +02:00
parent bd634f9742
commit 36fc5d3745
No known key found for this signature in database
2 changed files with 16 additions and 8 deletions

View file

@ -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(
try {
await this.httpClient.post(
'/',
JSON.stringify({
topic: this.topic,
...message,
}),
)
} catch (error: unknown) {
this.loggerService.error('ntfy client failed', { error })
}
}
}

View file

@ -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,