Invoke error callback if present instead of log callback (#93)

This commit is contained in:
Alex Damian
2018-06-20 12:11:24 -04:00
committed by Matias Fontanini
parent eb46b8808e
commit c5aca985b8
2 changed files with 16 additions and 10 deletions

View File

@@ -79,16 +79,19 @@ Consumer::~Consumer() {
rebalance_error_callback_ = nullptr;
close();
}
catch (const Exception& ex) {
const char* library_name = "cppkafka";
catch (const HandleException& ex) {
ostringstream error_msg;
error_msg << "Failed to close consumer [" << get_name() << "]: " << ex.what();
CallbackInvoker<Configuration::LogCallback> logger("log", get_configuration().get_log_callback(), nullptr);
if (logger) {
logger(*this, static_cast<int>(LogLevel::LOG_ERR), library_name, error_msg.str());
CallbackInvoker<Configuration::ErrorCallback> error_cb("error", get_configuration().get_error_callback(), this);
CallbackInvoker<Configuration::LogCallback> logger_cb("log", get_configuration().get_log_callback(), nullptr);
if (error_cb) {
error_cb(*this, static_cast<int>(ex.get_error().get_error()), error_msg.str());
}
else if (logger_cb) {
logger_cb(*this, static_cast<int>(LogLevel::LOG_ERR), "cppkafka", error_msg.str());
}
else {
rd_kafka_log_print(get_handle(), static_cast<int>(LogLevel::LOG_ERR), library_name, error_msg.str().c_str());
rd_kafka_log_print(get_handle(), static_cast<int>(LogLevel::LOG_ERR), "cppkafka", error_msg.str().c_str());
}
}
}