From 48deb87709e9d9a3249bcea1fe5dc4b0b3750883 Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Tue, 18 May 2021 12:34:08 -0400 Subject: [PATCH] fix: add null check when accessing undefined keys Co-authored-by: Hannes Kruse --- resources/skins.citizen.search/gateway/mwActionApi.js | 4 ++++ resources/skins.citizen.search/gateway/mwRestApi.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/skins.citizen.search/gateway/mwActionApi.js b/resources/skins.citizen.search/gateway/mwActionApi.js index 218d29e9..6db6510f 100644 --- a/resources/skins.citizen.search/gateway/mwActionApi.js +++ b/resources/skins.citizen.search/gateway/mwActionApi.js @@ -80,6 +80,10 @@ function convertDataToResults( data ) { const results = []; + if (typeof data?.query?.pages === 'undefined') { + return []; + } + /* eslint-disable-next-line compat/compat, es/no-object-values */ data = Object.values( data.query.pages ); diff --git a/resources/skins.citizen.search/gateway/mwRestApi.js b/resources/skins.citizen.search/gateway/mwRestApi.js index 9ef9fe75..6849dd47 100644 --- a/resources/skins.citizen.search/gateway/mwRestApi.js +++ b/resources/skins.citizen.search/gateway/mwRestApi.js @@ -22,7 +22,7 @@ function getUrl( input ) { function convertDataToResults( data ) { const results = []; - data = data.pages; + data = data?.pages ?? []; for ( let i = 0; i < data.length; i++ ) { results[ i ] = {