Tidy up NetworkError.
authorCarl Hetherington <cth@carlh.net>
Mon, 20 Dec 2021 20:45:21 +0000 (21:45 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 21 Dec 2021 20:03:07 +0000 (21:03 +0100)
src/lib/emailer.cc
src/lib/exceptions.cc
src/lib/exceptions.h

index 7bed7ef973093939d5f293347981ec0ee396f73a..f5812f0c20867eef7e79265c0862d2b400f29569 100644 (file)
@@ -231,7 +231,7 @@ Emailer::send (string server, int port, EmailProtocol protocol, string user, str
 
        auto const r = curl_easy_perform (curl);
        if (r != CURLE_OK) {
-               throw NetworkError (_("Failed to send email"), curl_easy_strerror(r));
+               throw NetworkError (_("Failed to send email"), string(curl_easy_strerror(r)));
        }
 
        curl_slist_free_all (recipients);
index 7e98a2b57c4fd95c4ec5cd038a0f4f9bc9869851..66db9fda71d0b13414515a697b8a8acced87810b 100644 (file)
@@ -116,8 +116,8 @@ KDMAsContentError::KDMAsContentError ()
 }
 
 
-NetworkError::NetworkError (string s, string d)
-       : runtime_error (String::compose("%1 (%2)", s, d))
+NetworkError::NetworkError (string s, optional<string> d)
+       : runtime_error (String::compose("%1%2", s, d ? String::compose(" (%1)", *d) : ""))
        , _summary (s)
        , _detail (d)
 {
index a8f095c22a2fba730ceb941286229424114d7236..2cae86accbbe4f823272a010544fb6cba5492051 100644 (file)
@@ -253,19 +253,19 @@ public:
 class NetworkError : public std::runtime_error
 {
 public:
-       explicit NetworkError (std::string s, std::string d = "");
+       explicit NetworkError (std::string s, boost::optional<std::string> d = boost::optional<std::string>());
 
        std::string summary () const {
                return _summary;
        }
 
-       std::string detail () const {
+       boost::optional<std::string> detail () const {
                return _detail;
        }
 
 private:
        std::string _summary;
-       std::string _detail;
+       boost::optional<std::string> _detail;
 };