From b760ded63b2cef2f062015330a9d6c31d157c414 Mon Sep 17 00:00:00 2001 From: Arnaud Ferrand Date: Fri, 7 Feb 2025 19:34:33 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20prevent=20error=20with=20?= =?UTF-8?q?no=20bounds=20attribute?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change prevents the plugin to thow an error when the `bounds` attribute is absent from the API result ✅ Closes: #421 --- src/providers/openCageProvider.ts | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/providers/openCageProvider.ts b/src/providers/openCageProvider.ts index 0f45ee2c1..384aa3703 100644 --- a/src/providers/openCageProvider.ts +++ b/src/providers/openCageProvider.ts @@ -1,4 +1,5 @@ import AbstractProvider, { + BoundsTuple, EndpointArgument, LatLng, ParseArgument, @@ -94,16 +95,22 @@ export default class OpenCageProvider extends AbstractProvider< } parse(response: ParseArgument): SearchResult[] { - return response.data.results.map((r) => ({ - x: r.geometry.lng, - y: r.geometry.lat, - label: r.formatted, - bounds: [ - [r.bounds.southwest.lat, r.bounds.southwest.lng], // s, w - [r.bounds.northeast.lat, r.bounds.northeast.lng], // n, e - ], - raw: r, - })); + return response.data.results.map((r) => { + let bounds = null; + if (r.bounds) { + bounds = [ + [r.bounds.southwest.lat, r.bounds.southwest.lng], // s, w + [r.bounds.northeast.lat, r.bounds.northeast.lng], // n, e + ] as BoundsTuple; + } + return { + x: r.geometry.lng, + y: r.geometry.lat, + label: r.formatted, + bounds, + raw: r, + }; + }); } async search(options: SearchArgument): Promise[]> {