Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(retry): return promise on loading success, otherwise retry #18

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
* @hCaptcha/react-reviewers

# Javascript Owners
*.js @hCaptcha/react-reviewers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets have both for these, I believe you can separate by comma or just duplicate line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved this change to separate PR

*.js @hCaptcha/hcaptcha-reviewers


# Github Action Owners
.github/actions @hCaptcha/react-reviewers
.github/workflow @hCaptcha/react-reviewers
.github/actions @hCaptcha/hcaptcha-reviewers
.github/workflow @hCaptcha/hcaptcha-reviewers
12 changes: 2 additions & 10 deletions lib/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,19 @@ export function hCaptchaApi(params: ILoaderParams = { cleanup: true }, sentry: S
data: script
});

hCaptchaScripts.push({ promise, scope: frame.window });
} catch(error) {
sentry.addBreadcrumb({
category: SENTRY_TAG,
message: 'hCaptcha failed to load',
data: error,
});


const scriptIndex = hCaptchaScripts.findIndex(script => script.scope === frame.window);

if (scriptIndex !== -1) {
hCaptchaScripts.splice(scriptIndex, 1);
}

sentry.captureException(error);
reject(new Error(SCRIPT_ERROR));
}
}
);

hCaptchaScripts.push({ promise, scope: frame.window });
return promise;
} catch (error) {
sentry.captureException(error);
Expand Down Expand Up @@ -119,7 +111,7 @@ export async function loadScript(params, retries = 0) {
return Promise.reject(error);
} else {
retries += 1;
return loadScript(params, retries);
return await loadScript(params, retries);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hcaptcha/loader",
"description": "This is a JavaScript library to easily configure the loading of the hCaptcha JS client SDK with built-in error handling.",
"version": "1.1.2",
"version": "1.1.3",
"author": "hCaptcha team and contributors",
"license": "MIT",
"keywords": [
Expand Down