From ad2892772d1ad83a83e1ee1aaa985ed86d164041 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sun, 22 May 2022 10:43:00 -0500 Subject: [PATCH] Catch non-arrays --- helpers/api/pagination.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/helpers/api/pagination.js b/helpers/api/pagination.js index 0100eaf..942c242 100644 --- a/helpers/api/pagination.js +++ b/helpers/api/pagination.js @@ -3,6 +3,12 @@ export const defaultPerPage = 20 export class PaginatedList { constructor({ list, perPage = defaultPerPage }) { + + // Catch errors if the list is not an array or a function + if ( !Array.isArray( list ) && typeof list !== 'function' ) { + throw new Error(`List must be an array or a function but is ${typeof list}`) + } + this.listArg = list this.perPage = perPage } @@ -17,6 +23,11 @@ export class PaginatedList { } get total () { + // Catch errors if the list is not an array or a function + if ( !Array.isArray( this.list ) ) { + throw new Error(`List must be an array or a function but is ${typeof list}`) + } + return this.list.length }