From c8993d1cd5ecd802703e718bc5bd8c2921d94246 Mon Sep 17 00:00:00 2001 From: Igwe Kalu Date: Fri, 20 Sep 2024 09:45:56 +0000 Subject: [PATCH] Implement null check for the 'findPaginatedResourcePath' function Previously the `deepFindPathToProperty` function would occasionally fail with `TypeError: Cannot read properties of null (reading 'hasOwnProperty')`. This change fixes that by adding a null check to the `findPaginatedResourcePath` function. Resolves #58 --- src/object-helpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/object-helpers.ts b/src/object-helpers.ts index 8c9714d..c57b467 100644 --- a/src/object-helpers.ts +++ b/src/object-helpers.ts @@ -4,11 +4,11 @@ const isObject = (value: any) => Object.prototype.toString.call(value) === "[object Object]"; function findPaginatedResourcePath(responseData: any): string[] { - const paginatedResourcePath = deepFindPathToProperty( + const paginatedResourcePath: string[] | null = deepFindPathToProperty( responseData, "pageInfo", ); - if (paginatedResourcePath.length === 0) { + if (paginatedResourcePath === null || paginatedResourcePath.length === 0) { throw new MissingPageInfo(responseData); } return paginatedResourcePath;