From e796696bf0e444fd916abb65ea6c589c4cc90d9e Mon Sep 17 00:00:00 2001 From: Faris Mahmutovic Date: Wed, 25 Oct 2023 16:15:05 +0200 Subject: [PATCH] fix: catch on load handler error --- src/index.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index e6b2af5..9c762ad 100644 --- a/src/index.js +++ b/src/index.js @@ -223,19 +223,25 @@ class HCaptcha extends React.Component { }); } - handleOnLoad () { + handleOnLoad () { this.setState({ isApiReady: true }, () => { - const element = getMountElement(this.props.scriptLocation); - const frame = getFrame(element); + try { + const element = getMountElement(this.props.scriptLocation); + const frame = getFrame(element); - this._hcaptcha = frame.window.hcaptcha; + this._hcaptcha = frame.window.hcaptcha; - // render captcha and wait for captcha id - this.renderCaptcha(() => { + + // render captcha and wait for captcha id + this.renderCaptcha(() => { // trigger onLoad if it exists + const { onLoad } = this.props; if (onLoad) onLoad(); - }); + }); + } catch (e) { + this.sentryHub?.captureException(e); + } }); }