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

View file

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