From 857257aafc8e597eeada2df9de5621f9c2e48995 Mon Sep 17 00:00:00 2001 From: Alexande B Date: Tue, 6 Feb 2024 19:58:44 +0100 Subject: [PATCH] fix: put back removed error-callback --- sdk/build.gradle | 2 +- sdk/src/main/html/hcaptcha.html | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/sdk/build.gradle b/sdk/build.gradle index 3808fc6..9dc1750 100644 --- a/sdk/build.gradle +++ b/sdk/build.gradle @@ -23,7 +23,7 @@ android { } defaultConfig { - minSdkVersion 16 + minSdkVersion 16 // Android 4.1 targetSdkVersion 34 // See https://developer.android.com/studio/publish/versioning diff --git a/sdk/src/main/html/hcaptcha.html b/sdk/src/main/html/hcaptcha.html index 1730195..e76c9cd 100644 --- a/sdk/src/main/html/hcaptcha.html +++ b/sdk/src/main/html/hcaptcha.html @@ -118,6 +118,24 @@ }, 'open-callback': function openCallback() { return BridgeObject.onOpen(); + }, + 'error-callback': function errorCallback(error) { + switch(error) { + case "rate-limited": + return BridgeObject.onError(31); + case "network-error": + return BridgeObject.onError(7); + case "invalid-data": + return BridgeObject.onError(8); + case "challenge-error": + return BridgeObject.onError(9); + case "internal-error": + return BridgeObject.onError(10); + default: + // Error not handled? Log it for debugging purposes + console.error(error); + return BridgeObject.onError(29); + } } }; } @@ -128,13 +146,13 @@ loadAsync: true, async: true, }; - }; + } function getLoaderParams(config) { var result = getScriptParams(config); result.render = 'explicit'; result.sentry = config.sentry; - result.custom = !!config.customTheme + result.custom = !!config.customTheme; result.assethost = config.assethost; result.imghost = config.imghost; result.reportapi = config.reportapi; @@ -145,7 +163,7 @@ result.cleanup = true; return result; - }; + } var container = document.getElementById("hcaptcha-container"); container.addEventListener("click", function () { if (hcaptcha) { @@ -157,7 +175,7 @@ }); async function execute() { try { - const { response } = await hcaptcha.execute(getScriptParams(bridgeConfig)); // { async: true } + var { response } = await hcaptcha.execute(getScriptParams(bridgeConfig)); BridgeObject.onPass(response); } catch (error) { switch(error) {