Skip to content

Commit

Permalink
fix: move errorCallback to upper level
Browse files Browse the repository at this point in the history
  • Loading branch information
CAMOBAP committed Jun 26, 2024
1 parent 857257a commit 6c8d7e3
Showing 1 changed file with 21 additions and 34 deletions.
55 changes: 21 additions & 34 deletions sdk/src/main/html/hcaptcha.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6c8d7e3

Please sign in to comment.