Skip to content

Commit 75b60db

Browse files
authored
fix: πŸ› prevent error with no bounds attribute (#422) closes #421
This change prevents the plugin to thow an error when the `bounds` attribute is absent from the API result βœ… Closes: #421
1 parent 522defb commit 75b60db

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

β€Žsrc/providers/openCageProvider.tsβ€Ž

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import AbstractProvider, {
2+
BoundsTuple,
23
EndpointArgument,
34
LatLng,
45
ParseArgument,
@@ -94,16 +95,22 @@ export default class OpenCageProvider extends AbstractProvider<
9495
}
9596

9697
parse(response: ParseArgument<RequestResult>): SearchResult<RawResult>[] {
97-
return response.data.results.map((r) => ({
98-
x: r.geometry.lng,
99-
y: r.geometry.lat,
100-
label: r.formatted,
101-
bounds: [
102-
[r.bounds.southwest.lat, r.bounds.southwest.lng], // s, w
103-
[r.bounds.northeast.lat, r.bounds.northeast.lng], // n, e
104-
],
105-
raw: r,
106-
}));
98+
return response.data.results.map((r) => {
99+
let bounds = null;
100+
if (r.bounds) {
101+
bounds = [
102+
[r.bounds.southwest.lat, r.bounds.southwest.lng], // s, w
103+
[r.bounds.northeast.lat, r.bounds.northeast.lng], // n, e
104+
] as BoundsTuple;
105+
}
106+
return {
107+
x: r.geometry.lng,
108+
y: r.geometry.lat,
109+
label: r.formatted,
110+
bounds,
111+
raw: r,
112+
};
113+
});
107114
}
108115

109116
async search(options: SearchArgument): Promise<SearchResult<RawResult>[]> {

0 commit comments

Comments
Β (0)