From 440f848c7c01b51ee6cde8a5a2d7c87a71467ed4 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 30 Aug 2017 15:12:24 +0200 Subject: [PATCH] Improve error handling for JSON-RPC calls refs #5450 --- lib/remote/jsonrpcconnection.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/remote/jsonrpcconnection.cpp b/lib/remote/jsonrpcconnection.cpp index 92c0e1c48..ca43a7c91 100644 --- a/lib/remote/jsonrpcconnection.cpp +++ b/lib/remote/jsonrpcconnection.cpp @@ -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")) { -- 2.50.1