From 3557a2ed90817291267002b498c6f453905048c8 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Thu, 8 Sep 2022 11:34:54 +0200 Subject: [PATCH] catch error for 2captcha --- src/workers/SolveCaptcha.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/workers/SolveCaptcha.js b/src/workers/SolveCaptcha.js index 0b73c82..a642967 100644 --- a/src/workers/SolveCaptcha.js +++ b/src/workers/SolveCaptcha.js @@ -39,26 +39,32 @@ class SolveCaptcha { status_code = status; solution = sol }) - await delay(5 * 1000) } handle_solution_received(solution) } async get_solution(catcha_id, onSolutionFound) { + console.log("get_solution() called") - let url_response = `http://2captcha.com/res.php?key=${API_KEY}&action=get&id=${catcha_id}`; - let res = await axios.get(url_response) - console.log(`statusCode: ${res.status}`); - console.log(res); - let results = res.data.split("|"); - let solution - if (results.length > 1) - solution = results[1]; - else { - solution = results[0] + try { + let url_response = `http://2captcha.com/res.php?key=${API_KEY}&action=get&id=${catcha_id}`; + let res = await axios.get(url_response) + console.log(`statusCode: ${res.status}`); + // console.log(res); + let results = res.data.split("|"); + let solution + if (results.length > 1) + solution = results[1]; + else { + solution = results[0] + } + onSolutionFound(res.status, solution) + await delay(5 * 1000) + } catch (e) { + onSolutionFound(1, CAPCHA_NOT_READY) + await delay(5 * 1000) } - onSolutionFound(res.status, solution) - await delay(5 * 1000) + } }