-
Notifications
You must be signed in to change notification settings - Fork 27
Description
Hey folks, maybe I'm hitting my limits of js/node.js knowledge, but I am having trouble understanding how to catch certain classes of error with this library in an async/promise context.
Specifically, node.js crashes if you pass an empty string query to the json method, eg:
let client = new serpapi.GoogleSearchResults(api_key)
client.json({}, (data) => {done();})
It looks like there used to be a unit test for this, but it has been removed.
10aadf8
"xit("fail:json", (done) => {"
Looking at the implementation, https://github.com/serpapi/google-search-results-nodejs/blob/master/lib/SerpApiSearch.js#L89C11-L89C16, it seems that any response from google that is not a 200 response will throw an exception that is impossible to catch, leading to dangling promises and node.js crashing.
Is the library broken? Is there a different pattern I should use to catch these exceptions?
I'm using the suggested pattern from this page: https://serpapi.com/integrations/node#promise-and-callback
const getJson = () => {
return new Promise((resolve) => {
search.json(params, resolve);
});
};