Skip to content

Commit

Permalink
fix(retry): return promise on loading success, otherwise retry
Browse files Browse the repository at this point in the history
  • Loading branch information
faris-imi committed Dec 13, 2023
1 parent 2c1e320 commit 1787912
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
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
*.js @IntuitionMachines/hcaptcha-reviewers


# Github Action Owners
.github/actions @hCaptcha/react-reviewers
.github/workflow @hCaptcha/react-reviewers
.github/actions @IntuitionMachines/hcaptcha-reviewers
.github/workflow @IntuitionMachines/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

0 comments on commit 1787912

Please sign in to comment.