Shadowblade911 / MrLancer-v2

ISC License
0 stars 0 forks source link

getRandomBookOfType() throws if the book type has no matching books #1

Closed jcotton42 closed 2 years ago

jcotton42 commented 2 years ago

getRandomBookOfType() will throw this exception if there is no books for the passed type in the database

/app/src/utils/postgresConnections.ts:5
import { BOOK, BOOK_TYPES, PROMPT as PROMPT_TYPE, DB_CONSTANTS, GUILD } from "../dbConstants/dbConstants";

TypeError: Cannot destructure property 'id' of 'randomSelection(...)' as it is undefined.
    at /app/src/utils/postgresConnections.ts:87:13
    at Generator.next (<anonymous>)
    at fulfilled (/app/src/utils/postgresConnections.ts:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

The culprit is this line

    const { id } = randomSelection(bookIds);