]> granicus.if.org Git - icinga2/commitdiff
Improve error handling for JSON-RPC calls
authorGunnar Beutner <gunnar.beutner@icinga.com>
Wed, 30 Aug 2017 13:12:24 +0000 (15:12 +0200)
committerGunnar Beutner <gunnar.beutner@icinga.com>
Tue, 12 Sep 2017 10:52:49 +0000 (12:52 +0200)
refs #5450

lib/remote/jsonrpcconnection.cpp

index 92c0e1c480fa16d4c5e21e3d675705ab321c054a..ca43a7c91be20aba22bc24c4e9e936b229e8074a 100644 (file)
@@ -202,7 +202,12 @@ void JsonRpcConnection::MessageHandler(const String& jsonString)
                ApiCallbackInfo aci = it->second;
                m_ApiCallbacks.erase(it);
 
-               aci.Callback(message);
+               try {
+                       aci.Callback(message);
+               } catch (const std::exception& ex) {
+                       Log(LogWarning, "JsonRpcConnection")
+                           << "Error while processing message for identity '" << m_Identity << "'\n" << DiagnosticInformation(ex);
+               }
 
                return;
        }
@@ -223,11 +228,10 @@ void JsonRpcConnection::MessageHandler(const String& jsonString)
                resultMessage->Set("result", afunc->Invoke(origin, message->Get("params")));
        } catch (const std::exception& ex) {
                /* TODO: Add a user readable error message for the remote caller */
-               resultMessage->Set("error", DiagnosticInformation(ex));
-               std::ostringstream info;
-               info << "Error while processing message for identity '" << m_Identity << "'";
+               String diagInfo = DiagnosticInformation(ex);
+               resultMessage->Set("error", diagInfo);
                Log(LogWarning, "JsonRpcConnection")
-                   << info.str() << "\n" << DiagnosticInformation(ex);
+                   << "Error while processing message for identity '" << m_Identity << "'\n" << diagInfo;
        }
 
        if (message->Contains("id")) {