Adding error handling for baanreserveren to take a screenshot on error
This commit is contained in:
parent
086950bb56
commit
630d68fa0c
1 changed files with 54 additions and 29 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue