未验证 提交 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 {
}
static void ServiceProtocolParameterError(rapidjson::Document& response,
std::string parameter_name) {
std::string error_details) {
auto& allocator = response.GetAllocator();
response.SetObject();
const int64_t kInvalidParams = -32602;
......@@ -781,11 +781,20 @@ static void ServiceProtocolParameterError(rapidjson::Document& response,
response.AddMember("message", "Invalid params", allocator);
{
rapidjson::Value details(rapidjson::kObjectType);
details.AddMember("details", parameter_name, allocator);
details.AddMember("details", error_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
bool Shell::OnServiceProtocolScreenshot(
const blink::ServiceProtocol::Handler::ServiceProtocolMap& params,
......@@ -803,8 +812,7 @@ bool Shell::OnServiceProtocolScreenshot(
response.AddMember("screenshot", image, allocator);
return true;
}
ServiceProtocolParameterError(response,
"Could not capture image screenshot.");
ServiceProtocolFailureError(response, "Could not capture image screenshot.");
return false;
}
......@@ -825,7 +833,7 @@ bool Shell::OnServiceProtocolScreenshotSKP(
response.AddMember("skp", skp, allocator);
return true;
}
ServiceProtocolParameterError(response, "Could not capture SKP screenshot.");
ServiceProtocolFailureError(response, "Could not capture SKP screenshot.");
return false;
}
......@@ -897,7 +905,8 @@ bool Shell::OnServiceProtocolRunInView(
return true;
} else {
FML_DLOG(ERROR) << "Could not run configuration in engine.";
response.AddMember("type", "Failure", allocator);
ServiceProtocolFailureError(response,
"Could not run configuration in engine.");
return false;
}
......@@ -951,7 +960,7 @@ bool Shell::OnServiceProtocolSetAssetBundlePath(
return true;
} else {
FML_DLOG(ERROR) << "Could not update asset directory.";
response.AddMember("type", "Failure", allocator);
ServiceProtocolFailureError(response, "Could not update asset directory.");
return false;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册