From 6c8d7e34c9573a7354576cef7f1ec66c65a1877d Mon Sep 17 00:00:00 2001 From: Alexande B Date: Tue, 6 Feb 2024 20:21:14 +0100 Subject: [PATCH] fix: move errorCallback to upper level --- sdk/src/main/html/hcaptcha.html | 55 +++++++++++++-------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/sdk/src/main/html/hcaptcha.html b/sdk/src/main/html/hcaptcha.html index e76c9cd..99d15c8 100644 --- a/sdk/src/main/html/hcaptcha.html +++ b/sdk/src/main/html/hcaptcha.html @@ -84,6 +84,25 @@ hcaptcha.reset(); } + 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); + } + } + function getTheme(config) { var theme = config.theme; var customTheme = config.customTheme; @@ -119,24 +138,7 @@ '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); - } - } + 'error-callback': errorCallback }; } function getScriptParams(config) { @@ -178,22 +180,7 @@ var { response } = await hcaptcha.execute(getScriptParams(bridgeConfig)); BridgeObject.onPass(response); } catch (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); - } + errorCallback(error); } } async function loadApi(config) {