Skip to content

Commit c80d419

Browse files
committed
fix: dispatch error event when invalid API key is provided
Not catching this error means nothing gets rendered because it just crashes, which isn’t very nice.
1 parent 9f7d82b commit c80d419

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/autocomplete/autocomplete.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ export default ({
4444
// deep compare is used to to only instantiate a new autocomplete API client if
4545
// required properties for it change
4646
useDeepCompareEffect(() => {
47-
autocomplete.current = createAutocomplete(apiKey, params, {
48-
...options,
49-
client: `ge-autocomplete${typeof VERSION !== 'undefined' ? `-${VERSION}` : ''}`
50-
})
47+
try {
48+
autocomplete.current = createAutocomplete(apiKey, params, {
49+
...options,
50+
client: `ge-autocomplete${typeof VERSION !== 'undefined' ? `-${VERSION}` : ''}`
51+
})
52+
} catch (err) {
53+
onError(err)
54+
}
5155
}, [apiKey, params, options])
5256

5357
// search queries the autocomplete API

0 commit comments

Comments
 (0)