Skip to content

Commit

Permalink
fix: πŸ› prevent error with no bounds attribute (#422) closes #421
Browse files Browse the repository at this point in the history
This change prevents the plugin to thow an error when the `bounds`
attribute is absent from the API result

βœ… Closes: #421
  • Loading branch information
tsamaya authored Feb 8, 2025
1 parent 522defb commit 75b60db
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/providers/openCageProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AbstractProvider, {
BoundsTuple,
EndpointArgument,
LatLng,
ParseArgument,
Expand Down Expand Up @@ -94,16 +95,22 @@ export default class OpenCageProvider extends AbstractProvider<
}

parse(response: ParseArgument<RequestResult>): SearchResult<RawResult>[] {
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<SearchResult<RawResult>[]> {
Expand Down

0 comments on commit 75b60db

Please sign in to comment.