forked from Mirrorlandia_minetest/minetest
Don't print whole json data buffer to errorstream on error
`errorstream` must not be overly verbose as clientside it is directly printed onto the ingame chat window. These days, the serverlist can contain > 200k bytes, so better print it to warningstream if the data buffer is too long.
This commit is contained in:
parent
e52ebda8b2
commit
860d70bd0e
@ -52,7 +52,13 @@ Json::Value fetchJsonValue(const std::string &url,
|
|||||||
if (!reader.parse(stream, root)) {
|
if (!reader.parse(stream, root)) {
|
||||||
errorstream << "URL: " << url << std::endl;
|
errorstream << "URL: " << url << std::endl;
|
||||||
errorstream << "Failed to parse json data " << reader.getFormattedErrorMessages();
|
errorstream << "Failed to parse json data " << reader.getFormattedErrorMessages();
|
||||||
|
if (fetch_result.data.size() > 100) {
|
||||||
|
errorstream << "Data (" << fetch_result.data.size()
|
||||||
|
<< " bytes) printed to warningstream." << std::endl;
|
||||||
|
warningstream << "data: \"" << fetch_result.data << "\"" << std::endl;
|
||||||
|
} else {
|
||||||
errorstream << "data: \"" << fetch_result.data << "\"" << std::endl;
|
errorstream << "data: \"" << fetch_result.data << "\"" << std::endl;
|
||||||
|
}
|
||||||
return Json::Value();
|
return Json::Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,8 +161,14 @@ int ModApiUtil::l_parse_json(lua_State *L)
|
|||||||
if (!reader.parse(stream, root)) {
|
if (!reader.parse(stream, root)) {
|
||||||
errorstream << "Failed to parse json data "
|
errorstream << "Failed to parse json data "
|
||||||
<< reader.getFormattedErrorMessages();
|
<< reader.getFormattedErrorMessages();
|
||||||
errorstream << "data: \"" << jsonstr << "\""
|
size_t jlen = strlen(jsonstr);
|
||||||
<< std::endl;
|
if (jlen > 100) {
|
||||||
|
errorstream << "Data (" << jlen
|
||||||
|
<< " bytes) printed to warningstream." << std::endl;
|
||||||
|
warningstream << "data: \"" << jsonstr << "\"" << std::endl;
|
||||||
|
} else {
|
||||||
|
errorstream << "data: \"" << jsonstr << "\"" << std::endl;
|
||||||
|
}
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user