Skip to content

Commit be15251

Browse files
committed
Protect against null result
1 parent 8fd9ab4 commit be15251

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/api.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ const createZeroTrustList = (name, items) =>
4646

4747
/**
4848
* Patches an existing list. Remove/append entries to the list.
49-
*
49+
*
5050
* API docs: https://developers.cloudflare.com/api/operations/zero-trust-lists-patch-zero-trust-list
5151
* @param {string} listId The ID of the list to patch
5252
* @param {Object} patch The changes to make
5353
* @param {string[]} patch.remove A list of the item values you want to remove.
5454
* @param {Object[]} patch.append Items to add to the list.
5555
* @param {string} patch.append[].value The domain of an entry.
56-
* @returns
57-
*/
58-
const patchExistingList = (listId, patch) =>
56+
* @returns
57+
*/
58+
const patchExistingList = (listId, patch) =>
5959
requestGateway(`/lists/${listId}`, {
6060
method: "PATCH",
6161
body: JSON.stringify(patch),
@@ -75,9 +75,9 @@ export const synchronizeZeroTrustLists = async (items) => {
7575

7676
console.log("Checking existing lists...");
7777
const { result: lists } = await getZeroTrustLists();
78-
const cgpsLists = lists.filter(({ name }) => name.startsWith("CGPS List"));
78+
const cgpsLists = lists?.filter(({ name }) => name.startsWith("CGPS List")) || [];
7979
console.log(`Found ${cgpsLists.length} existing lists. Calculating diffs...`);
80-
80+
8181
const domainsByList = {};
8282
// Do this sequentially to avoid rate-limits
8383
for (const list of cgpsLists) {
@@ -293,9 +293,9 @@ export const createZeroTrustRule = async (wirefilterExpression, name = "CGPS Fil
293293
* Updates a Zero Trust rule.
294294
*
295295
* API docs: https://developers.cloudflare.com/api/operations/zero-trust-gateway-rules-update-zero-trust-gateway-rule
296-
* @param {number} id The ID of the rule to be updated.
296+
* @param {number} id The ID of the rule to be updated.
297297
* @param {string} wirefilterExpression The expression to be used for the rule.
298-
* @param {string} name The name of the rule.
298+
* @param {string} name The name of the rule.
299299
* @param {string[]} filters The filters to be used for the rule.
300300
* @returns {Promise<Object>}
301301
*/

0 commit comments

Comments
 (0)