From 8bff9d93184fb8a7f1cb4bb83041edc8e4c0ee4c Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Tue, 2 Apr 2024 10:51:19 -0400 Subject: [PATCH] refactor: address pr feedback --- handler.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/handler.ts b/handler.ts index b5259b7..21ae889 100644 --- a/handler.ts +++ b/handler.ts @@ -89,8 +89,8 @@ export const makeGeocoderRequests = async ( const peliasQSP = { ...event.queryStringParameters } delete peliasQSP.layers - // Run both requests in parallel - let responses: FeatureCollection[] = await Promise.all( + // Run all requests in parallel + const uncheckedResponses: FeatureCollection[] = await Promise.all( geocoders.map((geocoder) => cachedGeocoderRequest(getGeocoder(geocoder), apiMethod, { ...convertQSPToGeocoderArgs(event.queryStringParameters), @@ -99,8 +99,9 @@ export const makeGeocoderRequests = async ( ) ) - responses = await Promise.all( - responses.map(async (response, index) => { + // Check if responses are satisfactory, and re-do them if needed + const responses = await Promise.all( + uncheckedResponses.map(async (response, index) => { // If backup geocoder is present, and the returned results are garbage, use the backup geocoder // if one is configured. This request will not be cached if ( @@ -111,7 +112,6 @@ export const makeGeocoderRequests = async ( ) ) { const backupGeocoder = getGeocoder(backupGeocoders[index]) - console.log('backup geocoder used!') return await backupGeocoder[apiMethod]( convertQSPToGeocoderArgs(event.queryStringParameters) ) @@ -128,6 +128,7 @@ export const makeGeocoderRequests = async ( if (idx === 0) return cur return mergeResponses({ customResponse: cur, primaryResponse: prev }) }, + // TODO: clean this reducer up. See https://github.com/ibi-group/pelias-stitch/pull/28#discussion_r1547582739 { features: [], type: 'FeatureCollection' } )