verto-health / ngx-turnstile

Cloudflare Turnstile for Angular
https://ngx-turnstile.pages.dev/
MIT License
62 stars 13 forks source link

Add error callback #27

Closed wilson-ascenda closed 7 months ago

wilson-ascenda commented 7 months ago

Summary

Make ngx-turnstile emit error code when the widget encounters an error.

Motivation

Currently, ngx-turnstile doesn't pass any error-callback configuration to the Turnstile widget, so by default "Turnstile will throw a JavaScript exception upon error". This may cause quite a lot of noise in error tracking systems like Rollbar.

This PR adds an error-callback that emits the error code as a component output.

ngx-turnstile users can subscribe to this error code and handle it according to their needs, which helps to address issue #26.

Caveats

Ideally, the ngx-turnstile component should accept a callback Function as input:

However, I'm not sure how to implement that, so I've replicated the EventEmitter approach from the resolved output. Now, in order to intercept the error code, ngx-turnstile will always pass 'error-callback' to the Turnstile widget.

Warning: breaking changes

The caveats above would mean that ngx-turnstile users will no longer see exceptions being thrown. Instead, they'll see the error code logged as a console warning.

(It would be great if someone could help with avoiding this breaking change!)

wilson-ascenda commented 7 months ago

Hi @choyiny @AleksanderBodurri

Thank you for the reviews, can we proceed to merge & release the changes please?

AleksanderBodurri commented 7 months ago

Thanks for the PR @wilson-ascenda 🙏 Will publish the latest release later today

wilson-ascenda commented 7 months ago

Great to hear. Thanks!