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

fix(browse): expose original error from browse request #1042

Merged
merged 3 commits into from
Feb 28, 2020

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Feb 28, 2020

Wrapping the original function in a new Promise swallowed its errors, and thus if there was some kind of error, you'd get an "unhandled promise" error like this:

(node:52050) UnhandledPromiseRejectionWarning: #<Object>
(node:52050) 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(). (rejection id: 1)
(node:52050) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

instead of something like:

{
  name: 'ApiError',
  message: 'Index prod_dictionaries does not exist',
  status: 404,
  transporterStackTrace: [
    {
      request: [Object],
      response: [Object],
      host: [Object],
      triesLeft: 3
    }
  ]
}
code to get that error
const fs = require('fs')
const algoliasearch = require('algoliasearch')
const client = algoliasearch('xxx', 'xxx')
const index = client.initIndex('xxx_invalid_index')
let hits = []
index
  .browseObjects({
    batch: objects => (hits = hits.concat(objects)),
  })
  .then(() => {
    console.log('Finished!')
    console.log('We got %d hits', hits.length)
    fs.writeFile('browse.json', JSON.stringify(hits, null, 2), 'utf-8', err => {
      if (err) throw err
      console.log('Your index has been exported!')
    })
  })
  .catch(e => {
    console.log(e)
  })

@Haroenv
Copy link
Contributor Author

Haroenv commented Feb 28, 2020

The errors on CI seem unrelated, right @nunomaduro ?

@nunomaduro
Copy link
Contributor

Tests on the CI fixed.

@nunomaduro
Copy link
Contributor

nunomaduro commented Feb 28, 2020

Good for me, debugging wy CI is failing on browser testing ( never failed before ).

@nunomaduro nunomaduro merged commit f83a911 into master Feb 28, 2020
@nunomaduro nunomaduro deleted the fix/browse-error branch February 28, 2020 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants