Skip to content

Commit

Permalink
Fix web service crash(issue:#4398) (#4405)
Browse files Browse the repository at this point in the history
* when we use flags put interface, but we does not specify the body.
* The service will be crashed.
For example:
curl -X PUT xxx.xxx.xxx.xxxx:19559/flags
  • Loading branch information
Milittle authored Jul 13, 2022
1 parent d53486c commit 7ce81ee
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/webservice/SetFlagsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ void SetFlagsHandler::onBody(std::unique_ptr<folly::IOBuf> body) noexcept {
void SetFlagsHandler::onEOM() noexcept {
folly::dynamic flags;
try {
std::string body = body_->moveToFbString().toStdString();
flags = folly::parseJson(body);
if (flags.empty()) {
if (!body_) {
LOG(ERROR) << "Got an empty body";
err_ = HttpCode::E_UNPROCESSABLE;
} else {
std::string body = body_->moveToFbString().toStdString();
flags = folly::parseJson(body);
if (flags.empty()) {
err_ = HttpCode::E_UNPROCESSABLE;
}
}
} catch (const std::exception &e) {
LOG(ERROR) << "Fail to update flags: " << e.what();
Expand Down

0 comments on commit 7ce81ee

Please sign in to comment.