fingerprintjs / BotD

Bot detection library that runs in the browser. Detects automation tools and frameworks. No server required, runs 100% on the client. MIT license, no usage restrictions.

Home Page:https://fingerprintjs.github.io/BotD/main/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When no token is provided an error is returned into `then` callback.

Valve opened this issue · comments

commented

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.

commented

@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
}
commented

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.