https://bugs.documentfoundation.org/show_bug.cgi?id=174490
--- Comment #1 from jirib79 <[email protected]> --- I made a fix with gemini-3.8-flash and this is the result: - a text set as Italian, while, in fact, it is an English text - Error reading data from the Internet. Server error message: HTTP 400: Error: Text checking was stopped due to too many errors (more that 60% of words seem to have an error). Are you sure you have set the correct text language? Language set: Italian, text length: 852. - in MITMProxy: * Request: 2026-11-15 13:15:11 POST https://api.languagetool.org/v2/check HTTP/2.0 ← 400 196b 225ms Request Response Detail user-agent: LibreOffice 26.2.7.3 denylistedbackend/8.18.0 OpenSSL/3.5.9 accept: */* content-length: 1165 content-type: application/x-www-form-urlencoded URL-encoded [m:auto] text: Over the last decades the official ... language: it * Response: date: Sun, 15 Nov 2026 12:15:12 GMT access-control-allow-origin: * content-length: 196 x-envoy-upstream-service-time: 71 server: istio-envoy x-backend-server: gcp_k8s_service_56 x-request-id: B952:00000000000000000000FFFFA2375371:01BB:6AF9A24F:B8E35E:F832D strict-transport-security: max-age=63072000 Raw [m:auto] Error: Text checking was stopped due to too many errors (more than 60% of words seem to have an error). Are you sure you have set the correct text language? Language set: Italian, text length: 852 So, the error is a bit clearer now. Please note, that this is gemini-3.8-flash diff, and that I'm unable to fully review it. ---%>--- --- a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx +++ b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx @@ -56,6 +56,8 @@ #include <com/sun/star/task/InteractionHandler.hpp> #include <com/sun/star/text/TextMarkupType.hpp> #include <com/sun/star/ucb/InteractiveNetworkConnectException.hpp> +#include <com/sun/star/ucb/InteractiveNetworkReadException.hpp> +#include <com/sun/star/ucb/InteractiveNetworkResolveNameException.hpp> #include <com/sun/star/uno/Any.hxx> #include <comphelper/interaction.hxx> #include <comphelper/propertyvalue.hxx> @@ -197,7 +199,6 @@ OString aURL8 = OUStringToOString(aURL, RTL_TEXTENCODING_UTF8); (void)curl_easy_setopt(curl.get(), CURLOPT_HTTPHEADER, pHttpHeader); - (void)curl_easy_setopt(curl.get(), CURLOPT_FAILONERROR, 1L); (void)curl_easy_setopt(curl.get(), CURLOPT_URL, aURL8.getStr()); (void)curl_easy_setopt(curl.get(), CURLOPT_TIMEOUT, 10L); // (void)curl_easy_setopt(curl.get(), CURLOPT_VERBOSE, 1L); @@ -388,8 +389,48 @@ return {}; } -void lclShowCURLErrorInteraction(const css::uno::Reference<css::uno::XComponentContext>& xContext, - CURLcode eCURLCode, const OUString& rServer) +OUString lclGetHttpErrorMessage(tools::Long nStatusCode, const std::string& rResponseBody) +{ + OUString aMsg = "HTTP " + OUString::number(nStatusCode); + if (rResponseBody.empty()) + return aMsg; + + std::string sText; + if (rResponseBody.starts_with("{")) + { + try + { + std::stringstream aStream(rResponseBody); + boost::property_tree::ptree aRoot; + boost::property_tree::read_json(aStream, aRoot); + if (auto oMsg = aRoot.get_optional<std::string>("message")) + sText = *oMsg; + else if (auto oErr = aRoot.get_optional<std::string>("error")) + sText = *oErr; + } + catch (const boost::property_tree::ptree_error&) + { + } + } + + if (sText.empty() && !rResponseBody.starts_with("<")) + { + sText = rResponseBody; + } + + if (!sText.empty()) + { + while (!sText.empty() && (sText.back() == '\n' || sText.back() == '\r' || sText.back() == ' ')) + sText.pop_back(); + if (!sText.empty()) + aMsg += ": " + OStringToOUString(sText, RTL_TEXTENCODING_UTF8); + } + + return aMsg; +} + +void lclShowHttpErrorInteraction(const css::uno::Reference<css::uno::XComponentContext>& xContext, + tools::Long nStatusCode, const std::string& rResponseBody) { if (!xContext.is()) return; @@ -407,12 +448,49 @@ pApprove }; - ucb::InteractiveNetworkConnectException aException( - { "(" + OUString::number(eCURLCode) + ") " - + OStringToOUString(curl_easy_strerror(eCURLCode), RTL_TEXTENCODING_UTF8) }, - {}, task::InteractionClassification_ERROR, rServer); + OUString aMessage = lclGetHttpErrorMessage(nStatusCode, rResponseBody); + ucb::InteractiveNetworkReadException aException( + aMessage, {}, task::InteractionClassification_ERROR, aMessage); aInteraction <<= aException; + xInteractionHandler->handle( + framework::InteractionRequest::CreateRequest(aInteraction, aContinuations)); +} + +void lclShowCURLErrorInteraction(const css::uno::Reference<css::uno::XComponentContext>& xContext, + CURLcode eCURLCode, const OUString& rServer) +{ + if (!xContext.is()) + return; + + css::uno::Reference<task::XInteractionHandler2> xInteractionHandler + = task::InteractionHandler::createWithParent(xContext, nullptr); + if (!xInteractionHandler.is()) + return; + + css::uno::Any aInteraction; + + rtl::Reference<comphelper::OInteractionApprove> pApprove + = new comphelper::OInteractionApprove(); + css::uno::Sequence<css::uno::Reference<css::task::XInteractionContinuation>> aContinuations{ + pApprove + }; + + if (eCURLCode == CURLE_COULDNT_RESOLVE_HOST) + { + ucb::InteractiveNetworkResolveNameException aException( + {}, {}, task::InteractionClassification_ERROR, rServer); + aInteraction <<= aException; + } + else + { + ucb::InteractiveNetworkConnectException aException( + { "(" + OUString::number(eCURLCode) + ") " + + OStringToOUString(curl_easy_strerror(eCURLCode), RTL_TEXTENCODING_UTF8) }, + {}, task::InteractionClassification_ERROR, rServer); + aInteraction <<= aException; + } + xInteractionHandler->handle( framework::InteractionRequest::CreateRequest(aInteraction, aContinuations)); } @@ -587,10 +665,16 @@ maLastErrorCheckerURL = checkerURL; lclShowCURLErrorInteraction(mxContext, eCURLCode, checkerURL); } + return xRes; } if (http_code != 200) { + if (maLastErrorCheckerURL != checkerURL) + { + maLastErrorCheckerURL = checkerURL; + lclShowHttpErrorInteraction(mxContext, http_code, response_body); + } return xRes; } ---%<--- -- You are receiving this mail because: You are the assignee for the bug.
