未验证 提交 2f4a0220 编写于 作者: J Jason Simmons 提交者: GitHub

Return proper JSON-RPC error responses from service protocol failures (#5889)

Fixes https://github.com/flutter/flutter/issues/19571
上级 d34eb1db
...@@ -773,7 +773,7 @@ Shell::GetServiceProtocolDescription() const { ...@@ -773,7 +773,7 @@ Shell::GetServiceProtocolDescription() const {
} }
static void ServiceProtocolParameterError(rapidjson::Document& response, static void ServiceProtocolParameterError(rapidjson::Document& response,
std::string parameter_name) { std::string error_details) {
auto& allocator = response.GetAllocator(); auto& allocator = response.GetAllocator();
response.SetObject(); response.SetObject();
const int64_t kInvalidParams = -32602; const int64_t kInvalidParams = -32602;
...@@ -781,11 +781,20 @@ static void ServiceProtocolParameterError(rapidjson::Document& response, ...@@ -781,11 +781,20 @@ static void ServiceProtocolParameterError(rapidjson::Document& response,
response.AddMember("message", "Invalid params", allocator); response.AddMember("message", "Invalid params", allocator);
{ {
rapidjson::Value details(rapidjson::kObjectType); rapidjson::Value details(rapidjson::kObjectType);
details.AddMember("details", parameter_name, allocator); details.AddMember("details", error_details, allocator);
response.AddMember("data", details, allocator); response.AddMember("data", details, allocator);
} }
} }
static void ServiceProtocolFailureError(rapidjson::Document& response,
std::string message) {
auto& allocator = response.GetAllocator();
response.SetObject();
const int64_t kJsonServerError = -32000;
response.AddMember("code", kJsonServerError, allocator);
response.AddMember("message", message, allocator);
}
// Service protocol handler // Service protocol handler
bool Shell::OnServiceProtocolScreenshot( bool Shell::OnServiceProtocolScreenshot(
const blink::ServiceProtocol::Handler::ServiceProtocolMap& params, const blink::ServiceProtocol::Handler::ServiceProtocolMap& params,
...@@ -803,8 +812,7 @@ bool Shell::OnServiceProtocolScreenshot( ...@@ -803,8 +812,7 @@ bool Shell::OnServiceProtocolScreenshot(
response.AddMember("screenshot", image, allocator); response.AddMember("screenshot", image, allocator);
return true; return true;
} }
ServiceProtocolParameterError(response, ServiceProtocolFailureError(response, "Could not capture image screenshot.");
"Could not capture image screenshot.");
return false; return false;
} }
...@@ -825,7 +833,7 @@ bool Shell::OnServiceProtocolScreenshotSKP( ...@@ -825,7 +833,7 @@ bool Shell::OnServiceProtocolScreenshotSKP(
response.AddMember("skp", skp, allocator); response.AddMember("skp", skp, allocator);
return true; return true;
} }
ServiceProtocolParameterError(response, "Could not capture SKP screenshot."); ServiceProtocolFailureError(response, "Could not capture SKP screenshot.");
return false; return false;
} }
...@@ -897,7 +905,8 @@ bool Shell::OnServiceProtocolRunInView( ...@@ -897,7 +905,8 @@ bool Shell::OnServiceProtocolRunInView(
return true; return true;
} else { } else {
FML_DLOG(ERROR) << "Could not run configuration in engine."; FML_DLOG(ERROR) << "Could not run configuration in engine.";
response.AddMember("type", "Failure", allocator); ServiceProtocolFailureError(response,
"Could not run configuration in engine.");
return false; return false;
} }
...@@ -951,7 +960,7 @@ bool Shell::OnServiceProtocolSetAssetBundlePath( ...@@ -951,7 +960,7 @@ bool Shell::OnServiceProtocolSetAssetBundlePath(
return true; return true;
} else { } else {
FML_DLOG(ERROR) << "Could not update asset directory."; FML_DLOG(ERROR) << "Could not update asset directory.";
response.AddMember("type", "Failure", allocator); ServiceProtocolFailureError(response, "Could not update asset directory.");
return false; return false;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册