willfrew/node-random-org

error on callback

komarevtsevdn opened this issue · 3 comments

i am using method generateSignedIntegers
Sometimes, throw error, but in callback have only result. how i can catch error and to call method once again or to make other action?

Hi, could you provide some example code that I can run that demonstrates the error you're seeing? Thanks.

it can be any error, for example with server random.org or my network connection. i think it's need to handle and return error, like first argument of callback. In your code have handler for error (JSON not valid for example). But on promise i cant get error. I wanna send a query one again, after error, but now cant make it, coz on promise havent error argument

Sorry for the slow response, @komarevtsevdn.

As the API is Promise-based, you will need to handle the errors in one of two ways:

random.generateIntegers({ min: 1, max: 99, n: 2 })
.then(function(result) {
  console.log(result.random.data); // [55, 3]
})
.catch(function(error) {
  /* Do something with the error */
});

Or:

random.generateIntegers({ min: 1, max: 99, n: 2 })
.then(function onFulfilled(result) {
  console.log(result.random.data); // [55, 3]
}, function onError(error) {
  /* Do something with the error */
});

Let me know if this solves your problem.