From 71fe1410c29016f753e9a04dff7cbccbfd477181 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Thu, 8 Apr 2021 10:16:24 -0600 Subject: [PATCH] fix error handling --- extensions/googletranslate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/googletranslate.cpp b/extensions/googletranslate.cpp index d1c2951..c1e8749 100644 --- a/extensions/googletranslate.cpp +++ b/extensions/googletranslate.cpp @@ -149,8 +149,8 @@ std::pair Translate(const std::wstring& text) FormatString(L"/m?sl=%s&tl=%s&q=%s", translateFrom.Copy(), translateTo.Copy(), Escape(text)).c_str() }) { - auto start = httpRequest.response.find(L"result-container\">") + 18, end = httpRequest.response.find(L'<', start); - if (start != end) return { true, HTML::Unescape(httpRequest.response.substr(start, end - start)) }; + auto start = httpRequest.response.find(L"result-container\">"), end = httpRequest.response.find(L'<', start); + if (end != std::string::npos) return { true, HTML::Unescape(httpRequest.response.substr(start + 18, end - start - 18)) }; return { false, FormatString(L"%s: %s", TRANSLATION_ERROR, httpRequest.response) }; } else return { false, FormatString(L"%s (code=%u)", TRANSLATION_ERROR, httpRequest.errorCode) };