Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
catch all exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
weigon committed Jun 15, 2018
1 parent d82faaa commit ceaee07
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions src/http/src/http_server_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,35 +264,43 @@ static void init(PluginFuncEnv* env) {
}

// assume there is only one section for us
//
try {
for (const mysql_harness::ConfigSection* section: info->config->sections()) {
if (section->name != kSectionName) {
continue;
}

for (const mysql_harness::ConfigSection* section: info->config->sections()) {
if (section->name != kSectionName) {
continue;
}

if (has_started) {
// ignore all the other sections for now
continue;
}
if (has_started) {
// ignore all the other sections for now
continue;
}

has_started = true;
has_started = true;

PluginConfig config {section};
PluginConfig config {section};

log_info("listening on %s:%u", config.srv_address.c_str(), config.srv_port);
log_info("listening on %s:%u", config.srv_address.c_str(), config.srv_port);

http_servers.emplace(
std::make_pair(section->name,
std::make_shared<HttpServer>(config.srv_address.c_str(), config.srv_port)));
http_servers.emplace(
std::make_pair(section->name,
std::make_shared<HttpServer>(config.srv_address.c_str(), config.srv_port)));

auto srv = http_servers.at(section->name);
HttpServerComponent::getInstance().init(srv);
auto srv = http_servers.at(section->name);
HttpServerComponent::getInstance().init(srv);

if (!config.static_basedir.empty()) {
srv->add_route("",
std::unique_ptr<HttpStaticFolderHandler>(
new HttpStaticFolderHandler(config.static_basedir)));
if (!config.static_basedir.empty()) {
srv->add_route("",
std::unique_ptr<HttpStaticFolderHandler>(
new HttpStaticFolderHandler(config.static_basedir)));
}
}
} catch (const std::invalid_argument& exc) {
set_error(env, mysql_harness::kConfigInvalidArgument, "%s", exc.what());
} catch (const std::exception& exc) {
set_error(env, mysql_harness::kRuntimeError, "%s", exc.what());
} catch (...) {
set_error(env, mysql_harness::kUndefinedError, "Unexpected exception");
}
}

Expand Down Expand Up @@ -330,8 +338,12 @@ static void start(PluginFuncEnv* env) {
g_shutdown_pending = 1;

srv->join_all();
} catch (const std::invalid_argument& exc) {
set_error(env, mysql_harness::kConfigInvalidArgument, "%s", exc.what());
} catch (const std::exception& exc) {
set_error(env, mysql_harness::kRuntimeError, "%s", exc.what());
} catch (...) {
set_error(env, mysql_harness::kRuntimeError, "...");
set_error(env, mysql_harness::kUndefinedError, "Unexpected exception");
}
}

Expand Down

0 comments on commit ceaee07

Please sign in to comment.