summaryrefslogtreecommitdiff
path: root/indra/newview/lltranslate.cpp
diff options
context:
space:
mode:
authorAndrey Kleshchev <andreykproductengine@lindenlab.com>2023-05-23 23:06:41 +0300
committerAndrey Kleshchev <andreykproductengine@lindenlab.com>2023-05-23 23:06:41 +0300
commit6f7cba0f9111c85d32d9ec4e9f52be5e7fbaaf9e (patch)
treed68605edf19c3fb2bc08ad0614305769f8c113fe /indra/newview/lltranslate.cpp
parent863e7f22a75e9d9c9d5c1f826eac6cd0000edac0 (diff)
SL-19635 Better error handling
Diffstat (limited to 'indra/newview/lltranslate.cpp')
-rw-r--r--indra/newview/lltranslate.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/indra/newview/lltranslate.cpp b/indra/newview/lltranslate.cpp
index 70a40921ef..c37c955e8d 100644
--- a/indra/newview/lltranslate.cpp
+++ b/indra/newview/lltranslate.cpp
@@ -949,6 +949,8 @@ bool LLDeepLTranslationHandler::checkVerificationResponse(
const LLSD& response,
int status) const
{
+ // Might need to parse body to make sure we got
+ // a valid response and not a message
return status == HTTP_OK;
}
@@ -1000,7 +1002,6 @@ bool LLDeepLTranslationHandler::parseResponse(
{
return false;
}
-
detected_lang = data["detected_source_language"].asString();
LLStringUtil::toLower(detected_lang);
@@ -1019,8 +1020,22 @@ bool LLDeepLTranslationHandler::isConfigured() const
std::string LLDeepLTranslationHandler::parseErrorResponse(
const std::string& body)
{
- // DeepL doesn't seem to have any error handling beyoun http codes
- return std::string();
+ // Example: "{\"message\":\"One of the request inputs is not valid.\"}"
+
+ Json::Value root;
+ Json::Reader reader;
+
+ if (!reader.parse(body, root))
+ {
+ return std::string();
+ }
+
+ if (!root.isObject() || !root.isMember("message"))
+ {
+ return std::string();
+ }
+
+ return root["message"].asString();
}
// static