forked from Public-Mirror/Textractor
improve error handling and fix build
This commit is contained in:
parent
3b948c3359
commit
444974ee8a
@ -113,6 +113,6 @@ std::pair<bool, std::wstring> Translate(const std::wstring& text)
|
|||||||
FormatString(L"/ttranslatev3?fromLang=%s&to=%s&text=%s%s", translateFrom.Copy(), translateTo.Copy(), Escape(text), token.Copy()).c_str()
|
FormatString(L"/ttranslatev3?fromLang=%s&to=%s&text=%s%s", translateFrom.Copy(), translateTo.Copy(), Escape(text), token.Copy()).c_str()
|
||||||
})
|
})
|
||||||
if (auto translation = Copy(JSON::Parse(httpRequest.response)[0][L"translations"][0][L"text"].String())) return { true, translation.value() };
|
if (auto translation = Copy(JSON::Parse(httpRequest.response)[0][L"translations"][0][L"text"].String())) return { true, translation.value() };
|
||||||
else return { false, FormatString(L"%s: %s", TRANSLATION_ERROR, httpRequest.response) };
|
else return { false, FormatString(L"%s (token=%s): %s", TRANSLATION_ERROR, std::exchange(token.Acquire().contents, L""), httpRequest.response) };
|
||||||
else return { false, FormatString(L"%s (code=%u)", TRANSLATION_ERROR, httpRequest.errorCode) };
|
else return { false, FormatString(L"%s (code=%u)", TRANSLATION_ERROR, httpRequest.errorCode) };
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ extern Settings settings;
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
QLabel* statusLabel;
|
QLabel* statusLabel;
|
||||||
AutoHandle<> process;
|
AutoHandle<> process = NULL;
|
||||||
QWebSocket webSocket;
|
QWebSocket webSocket;
|
||||||
std::atomic<int> idCounter = 0;
|
std::atomic<int> idCounter = 0;
|
||||||
Synchronized<std::unordered_map<int, concurrency::task_completion_event<JSON::Value<wchar_t>>>> mapQueue;
|
Synchronized<std::unordered_map<int, concurrency::task_completion_event<JSON::Value<wchar_t>>>> mapQueue;
|
||||||
@ -161,7 +161,7 @@ namespace DevTools
|
|||||||
int id = idCounter += 1;
|
int id = idCounter += 1;
|
||||||
if (!Connected()) return {};
|
if (!Connected()) return {};
|
||||||
mapQueue->try_emplace(id, response);
|
mapQueue->try_emplace(id, response);
|
||||||
QMetaObject::invokeMethod(&webSocket, std::bind(&QWebSocket::sendTextMessage, webSocket, S(FormatString(LR"({"id":%d,"method":"%S","params":%s})", id, method, params))));
|
QMetaObject::invokeMethod(&webSocket, std::bind(&QWebSocket::sendTextMessage, &webSocket, S(FormatString(LR"({"id":%d,"method":"%S","params":%s})", id, method, params))));
|
||||||
try { if (auto result = create_task(response).get()[L"result"]) return result; } catch (...) {}
|
try { if (auto result = create_task(response).get()[L"result"]) return result; } catch (...) {}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user