fix 500 error

This commit is contained in:
2023-08-13 21:24:06 +02:00
parent f4c21e3c50
commit c532347fa2

View File

@@ -52,12 +52,12 @@ export class GetRandomCardInDeckHandler implements ICommandHandler<GetRandomCard
const randomCard = await this.getSmartRandomCard(cards) const randomCard = await this.getSmartRandomCard(cards)
if (!randomCard) { if (!randomCard) {
this.logger.error(`No cards found in deck with id ${randomCard.deckId}`, { this.logger.error(`No cards found in deck}`, {
previousCardId, previousCardId,
randomCard, randomCard,
cards, cards,
}) })
throw new NotFoundException(`No cards found in deck with id ${randomCard.deckId}`) throw new NotFoundException(`No cards found in deck`)
} }
if (randomCard.id === previousCardId && cards.length !== 1) { if (randomCard.id === previousCardId && cards.length !== 1) {
return this.getNotDuplicateRandomCard(cards, previousCardId) return this.getNotDuplicateRandomCard(cards, previousCardId)
@@ -78,6 +78,11 @@ export class GetRandomCardInDeckHandler implements ICommandHandler<GetRandomCard
command.userId, command.userId,
command.deckId command.deckId
) )
if (!cards.length) {
throw new NotFoundException(`No cards found in deck with id ${command.deckId}`)
}
const smartRandomCard = await this.getNotDuplicateRandomCard(cards, command.previousCardId) const smartRandomCard = await this.getNotDuplicateRandomCard(cards, command.previousCardId)
return { return {