From fffb63edf465a81ea1bdc3248caf751bd2652981 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Tue, 21 Aug 2018 23:41:30 -0400 Subject: [PATCH] google translate error handling --- extensions/googletranslate.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/extensions/googletranslate.cpp b/extensions/googletranslate.cpp index f7d0290..d748ac4 100644 --- a/extensions/googletranslate.cpp +++ b/extensions/googletranslate.cpp @@ -80,9 +80,12 @@ extern "C" WinHttpReceiveResponse(request, NULL); WinHttpReadData(request, buffer, 10000, &bytesRead); // Response formatted as JSON: starts with '[[["' - MultiByteToWideChar(CP_UTF8, 0, buffer + 4, (int)((strstr(buffer, "\",\"")) - (buffer + 4)), translation, 10000); - message = translation; - for (int i = -1; translation[++i];) if (translation[i] == L'\\') translation[i] = 0x200b; + if (buffer[0] == '[') + { + MultiByteToWideChar(CP_UTF8, 0, buffer + 4, (int)((strstr(buffer, "\",\"")) - (buffer + 4)), translation, 10000); + message = translation; + for (int i = -1; translation[++i];) if (translation[i] == L'\\') translation[i] = 0x200b; + } } WinHttpCloseHandle(request); }