Adding error handling for baanreserveren to take a screenshot on error

This commit is contained in:
Collin Duncan 2024-02-23 07:26:29 -06:00
parent 086950bb56
commit 630d68fa0c
No known key found for this signature in database
GPG key ID: 9584E0870D990D97

View file

@ -8,6 +8,7 @@ import dayjs from '../../common/dayjs'
import { LoggerService } from '../../logger/service.logger'
import { Reservation } from '../../reservations/entity'
import { EmptyPage } from '../pages/empty'
import path from 'path'
const BAAN_RESERVEREN_ROOT_URL = 'https://squashcity.baanreserveren.nl'
@ -81,6 +82,13 @@ export class BaanReserverenService {
)
}
private async handleError() {
await this.page.screenshot({
type: 'png',
path: path.resolve('.', `${Date.now()}_error-screenshot.png`),
}).catch((reason: any) => this.loggerService.warn('Failed to take screenshot', { reason }))
}
private async checkSession(username: string) {
this.loggerService.debug('Checking session', {
username,
@ -465,15 +473,24 @@ export class BaanReserverenService {
}
public async performReservation(reservation: Reservation) {
try {
await this.init(reservation)
await this.navigateToDay(reservation.dateRangeStart)
await this.selectAvailableTime(reservation)
await this.selectOwner(reservation.ownerId)
await this.selectOpponent(reservation.opponentId, reservation.opponentName)
await this.selectOpponent(
reservation.opponentId,
reservation.opponentName,
)
await this.confirmReservation()
} catch (error: unknown) {
await this.handleError()
throw error
}
}
public async addReservationToWaitList(reservation: Reservation) {
try {
await this.init(reservation)
await this.navigateToWaitingList()
const previousWaitingListIds = await this.recordWaitingListEntries()
@ -494,14 +511,22 @@ export class BaanReserverenService {
}
return waitingListId
} catch (error: unknown) {
await this.handleError()
throw error
}
}
public async removeReservationFromWaitList(reservation: Reservation) {
try {
if (!reservation.waitListed || !reservation.waitingListId) return
await this.init(reservation)
await this.navigateToWaitingList()
await this.deleteWaitingListEntryRowById(reservation.waitingListId)
} catch (error: unknown) {
await this.handleError()
throw error
}
}
}