Skip to content

Commit

Permalink
add better error management for AntiCaptcha
Browse files Browse the repository at this point in the history
  • Loading branch information
drallieiv committed Nov 9, 2017
1 parent 48216da commit 28e0bcf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void run() {
ErrorCode errorCode = ErrorCode.valueOf(response.getErrorCode());
logger.error("Captcha Provider Error {}", response.getErrorCode());

if (errorCode == ErrorCode.ERROR_ZERO_BALANCE) {
if (ErrorCode.ERROR_ZERO_BALANCE.equals(errorCode)) {
if (stopOnInsufficientBalance) {
logger.error("STOP");
this.runFlag = false;
Expand All @@ -153,10 +153,28 @@ public void run() {
// Interrupted
}
}
}else if (ErrorCode.ERROR_NO_SLOT_AVAILABLE.equals(errorCode)){
// No slots, wait for a bit
logger.warn("NO_SLOT_AVAILABLE, Wait for a bit");
try {
Thread.sleep(30000);
} catch (InterruptedException e1) {
// Interrupted
}
}else if (ErrorCode.ERROR_NO_SUCH_CAPCHA_ID.equals(errorCode)){
logger.warn("ERROR_NO_SUCH_CAPCHA_ID : {}", captchaId);
challenges.remove(challenge);
}else if (ErrorCode.ERROR_CAPTCHA_UNSOLVABLE.equals(errorCode)){
logger.warn("ERROR_CAPTCHA_UNSOLVABLE : {}", captchaId);
challenges.remove(challenge);
} else if (ErrorCode.ERROR_CAPTCHA_UNSOLVABLE.equals(errorCode)){
logger.warn("OTHER ERROR with code {}", errorCode);
// challenges.remove(challenge);
}

} catch (IllegalArgumentException e) {
logger.error("Unknown Captcha Provider Error Code : {}", response.getErrorCode());
challenges.remove(challenge);
}
} else {
// NO ERROR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,18 @@ public double getBalance() throws ImageTypersConfigurationException {
try {
Request sendRequest = buildBalanceCheckequestGet();
Response sendResponse = captchaClient.newCall(sendRequest).execute();
String balance = sendResponse.body().string();
return Double.valueOf(balance.replaceAll("\\$", ""));
} catch (Exception e) {

String body = sendResponse.body().string();
if(body.contains("ERROR")){
if(body.contains("AUTHENTICATION_FAILED")){
throw new ImageTypersConfigurationException("Authentication failed, captcha key might be bad");
}else{
throw new ImageTypersConfigurationException(body);
}
}

return Double.valueOf(body.replaceAll("\\$", ""));
} catch (IOException e) {
throw new ImageTypersConfigurationException("Error getting account balance", e);
}
}
Expand Down

0 comments on commit 28e0bcf

Please sign in to comment.