When no token is provided an error is returned into `then` callback.
Valve opened this issue · comments
All errors should be handled in catch
block instead. AFAIK, then
should be called for happy paths only.
@Finesse can confirm that.
It's a matter of code style. In JavaScript it's a common thing to throw errors instead of returning them, especially when errors are unexpected. Users will expect errors to be thrown in case of mistakes, so I'd change agent to make it throw errors.
Also basic checks can be done on client side in "load" phase. For example, agent can check that a not empty token is given. Even though TypeScript will check that the token
property is given, many customers may use plain JavaScript.
@Finesse in fpjs-pro, if I don't provide a token, will the error be provided in .then
or in .catch
?
@Valve In .catch
. Examples:
FingerprintJS.load({ token: '' }).catch((error) => {
// The missing token error will be here
})
try {
await FingerprintJS.load({ token: '' })
} catch (error) {
// The missing token error will be here
}
Yes, that was my point. In botd the catch will not be called, and the .then
will have a special response, which is an error.
I think it is incorrect.
@Valve It's controversial, but I think most of developers will agree that all errors must be thrown (sent to catch
).
The opposite point is that only unexpected errors must be thrown. I don't like it because expected and unexpected errors can be distinguished using the name
attribute and it's more convenient to handle all successful cases in then
and failed cases in catch
.
Done