handling incorrect captcha and check not found cases

This commit is contained in:
2024-11-28 00:28:37 +03:00
parent 47dfc19395
commit 4d658a817b
7 changed files with 81 additions and 13 deletions

View File

@@ -6,6 +6,7 @@
#include <locale>
#include <regex>
#include <string>
#include "../exceptions/ofdrequestexception.h"
std::string to_utf8(std::wstring wide_string) {
static std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_conv;
@@ -120,6 +121,15 @@ Check parseOfdRuAnswer(std::string html) {
std::vector<std::wstring> amounts = find_amounts_in_html(trimmed);
std::vector<std::wstring> prices = find_prices_in_html(trimmed);
if ((products.size() + amounts.size() + prices.size()) == 0) {
if (html == "Bad Request4") { // Failed to solve a captcha
throw OfdRequestException("Incorrect captcha");
} else { // Most likely that the check does not exist
throw OfdRequestException("Does not exist");
}
return Check();
}
if ((products.size() + amounts.size() + prices.size())/products.size() != 3) {
std::cerr << "An error has occured during the parsing of html. Please, contact the developer." << std::endl;
std::exit(-1);