diff --git a/configure.ac b/configure.ac index 30e2319182..2a84c712c1 100644 --- a/configure.ac +++ b/configure.ac @@ -79,7 +79,7 @@ AS_IF([test "x$with_cpprest" != "xno"], CPPFLAGS="$CPPFLAGS $CXXFLAGS $BOOST_CPPFLAGS" AC_CHECK_HEADERS([cpprest/http_client.h], [ - AC_MSG_CHECKING([for libcpprest >= 2.5]) + AC_MSG_CHECKING([for libcpprest >= 2.10.8]) old_LIBS="$LIBS" LIBS="-lcpprest $BOOST_SYSTEM_LIB $BOOST_THREAD_LIB -lssl -lcrypto $LIBS" AC_LINK_IFELSE([AC_LANG_PROGRAM( @@ -88,8 +88,8 @@ AS_IF([test "x$with_cpprest" != "xno"], #include ], [ - #if CPPREST_VERSION < 200500 - #error "cpprest >= 2.5 required" + #if CPPREST_VERSION < 201008 + #error "cpprest >= 2.10.8 required" #endif web::http::client::http_client c(U("https://poedit.net")); ])], diff --git a/src/Poedit-Prefix.pch b/src/Poedit-Prefix.pch index 7079c9557b..40adbbeeb1 100644 --- a/src/Poedit-Prefix.pch +++ b/src/Poedit-Prefix.pch @@ -12,7 +12,7 @@ #include "concurrency.h" #include "configuration.h" - + #include "errors.h" #include "unicode_helpers.h" #include "str_helpers.h" #endif diff --git a/src/errors.cpp b/src/errors.cpp index 7e3198ed87..6a20506405 100644 --- a/src/errors.cpp +++ b/src/errors.cpp @@ -25,6 +25,34 @@ #include "errors.h" +#include + +#ifndef __WXOSX__ +#include +#include +#endif + +namespace +{ + +inline wxString from_c_string(const char *msg) +{ + // try interpreting as UTF-8 first as the most likely one (from external sources) + wxString s = wxString::FromUTF8(msg); + if (!s.empty()) + return s; + + s = wxString(msg); + if (!s.empty()) + return s; + + // not in current locale either, fall back to Latin1 + return wxString(msg, wxConvISO8859_1); +} + +} // anonymous namespace + + wxString errors::detail::DescribeExceptionImpl(Rethrower& rethrower) { try @@ -36,21 +64,32 @@ wxString errors::detail::DescribeExceptionImpl(Rethrower& rethrower) { return e.What(); } - catch (const std::exception& e) +#ifndef __WXOSX__ + catch (const web::http::http_exception & e) { - const char *msg = e.what(); - // try interpreting as UTF-8 first as the most likely one (from external sources) - wxString s = wxString::FromUTF8(msg); - if (s.empty()) + // rephrase the errors more humanly; the default form is too cryptic + // also strip trailing newlines that C++REST tends to add + std::string msg(e.what()); + if (!boost::starts_with(msg, "WinHttp")) { - s = wxString(msg); - if (s.empty()) // not in current locale either, fall back to Latin1 - s = wxString(msg, wxConvISO8859_1); + boost::trim_right(msg); + return from_c_string(msg.c_str()); // preserve actual messages } - return s; + + msg = e.error_code().message(); + if (msg.empty()) + return from_c_string(e.what()); // give up + + boost::trim_right(msg); + return wxString::Format(_("Network error: %s (%d)"), from_c_string(msg.c_str()), e.error_code().value()); + } +#endif // !__WXOSX__ + catch (const std::exception& e) + { + return from_c_string(e.what()); } catch (...) { - return "unknown error"; + return _("Unknown error"); } }