Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnhandledPromiseRejectionWarning #317

Open
FilipeVoges opened this issue Oct 29, 2020 · 5 comments
Open

UnhandledPromiseRejectionWarning #317

FilipeVoges opened this issue Oct 29, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@FilipeVoges
Copy link

I am unable to perform any search, I saw that it has changed (updated) in various parts of the Google Cloud Platform (#306) .

Anyway, the output of executing my script was this, can someone help me?

$ node index.js
Type a Wikipedia search term: steve jobs

[1] Who is
[2] What is
[3] The history of
[0] CANCEL

Choose one option [1, 2, 3, 0]: 3
> [text-robot] Starting...
> [text-robot] Fetching content from Wikipedia
(node:16488) UnhandledPromiseRejectionWarning: Page id "steve bobs" does not mat
ch any pages. Try another id!
(node:16488) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This
 error originated either by throwing inside of an async function without a catch
 block, or by rejecting a promise which was not handled with .catch(). To termin
ate the node process on unhandled promise rejection, use the CLI flag `--unhandl
ed-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejecti
ons_mode). (rejection id: 1)
(node:16488) [DEP0018] DeprecationWarning: Unhandled promise rejections are depr
ecated. In the future, promise rejections that are not handled will terminate th
e Node.js process with a non-zero exit code.```
@HeavyBR
Copy link

HeavyBR commented Nov 5, 2020

I was having the same problem...

What i did here is change the auth settings in image.js for a new type of auth in google apis. Reading the googleapis docs, the custom search api supports Oauth2 and Service Accounts auth type. So, i created a new service account in GCP, with the required permissions for doing searchs, and changed the auth code on image.js to support service account auth.

Service Accounts GCP
Google API docs (Node.JS)

 const auth = new google.auth.GoogleAuth({
      // Scopes can be specified either as an array or as a single, space-delimited string.
      keyFile: 'your_api_key_file',
      scopes: ['https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cse'],
    });

    // Acquire an auth client, and bind it to all future calls
    const authClient = await auth.getClient();
    google.options({auth: authClient});


    const response = await customSearch.cse.list({
      auth: authClient,
      cx: googleSearchCredentials.searchEngineId,
      q: query,
      searchType: 'image',
      num: 2
    })

@andutra
Copy link

andutra commented Nov 19, 2020

I am getting the same error, when I try to replace the code with the @HeavyBR suggestion I get the error google.auth.GoogleAuth is not a constructor.

at image js I have this import:
const google = require('googleapis').google

If I remove .google at the end I get more errors with another imports.
I tried to add const googleapis = require('googleapis')
and replace google.auth.GoogleAuth for googleapis.auth.GoogleAuth and then I get the error (node:1245) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'GoogleAuth' of undefined

Can someone help?

@HeavyBR
Copy link

HeavyBR commented Nov 19, 2020

@andutra Try to update your googleapis package, i think that will fix the error.

npm update googleapis

@andutra
Copy link

andutra commented Nov 19, 2020

Doesn't work, I will try to rewrite this part of code tonight

@matbrgz matbrgz added the bug Something isn't working label Dec 4, 2020
@matbrgz
Copy link
Collaborator

matbrgz commented Dec 17, 2023

Hey any progress here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants