paylike/sdk

Error handler not called

Closed this issue · 5 comments

Hi,

We have a problem where in case of wrong/incomplete parameters the paylike.pay call does not call the "node-style": callback(error, response). In case of success, the callback is called, in case of errors it doesn't.

We use https://sdk.paylike.io/10.js

Sample code:

let params = {
    amount: {
        currency: 'bogus',
        exponent: 2,
        value: 'STRING!!!',
    },
}

// Set up paylike, paylike = Paylike({key: ...})
paylike.pay(params, (error, response) => {
        console.log('err:', error) // This should be the output in case of error, but it doesn't get called
})

Thank you!

We confirm also, this behaviour.

The callback should not be called in that case (call error). Instead, the paylike.pay call itself throws an immediate error. This matches the convention used by e.g. Node.js:

try {
  fs.readFile(true, err => console.log('Not called'))
} catch (err) {
  console.log('Called')
}

In my browser I see the following for your example:

Error: Paylike: Invalid "amount" value. Must be a positive integer, got "STRING!!!"

Feel free to reopen if you have more to add 🙂

Wrapping the code in try/catch solves the issue indeed. Thanks for the feedback!

However, IMHO the documentation is not clear enough. I suppose it depends on whether the error happens sync/async, and is not clear which errors can be caught directly and which ones will be passed to the callback. I think it would be helpful to update the documentation in this regard.

Thanks!

You're welcome.

We're always trying to find the sweet spot of being precise without providing overwhelming information, which I honestly do not find obvious. JavaScript uses a lot of idioms. We do write:

The callback is called in "node-style"

which we could link to a blog post explaining what that means, but I'm not sure many would click it anyway.
Frankly, you should consider any operation able to throw an exception and have some way of being alerted about those anyway.