提交 fec1c6de 编写于 作者: M millb

Fixed Error message and error code

上级 c5ba58f2
......@@ -457,7 +457,7 @@ namespace ErrorCodes
extern const int UNKNOWN_PROTOCOL = 480;
extern const int PATH_ACCESS_DENIED = 481;
extern const int DICTIONARY_ACCESS_DENIED = 482;
extern const int UNACCEPTABLE_URL = 483;
extern const int UNACCEPTABLE_URL = 485;
extern const int KEEPER_EXCEPTION = 999;
extern const int POCO_EXCEPTION = 1000;
......
......@@ -39,9 +39,9 @@ IStorageURLBase::IStorageURLBase(
: uri(uri_), context_global(context_), format_name(format_name_), table_name(table_name_), database_name(database_name_)
{
if (!checkHost(uri.getHost()) &&
!checkHost(uri.getHost() + ":" + Poco::NumberFormatter::format(uri.getPort())))
!checkHost(uri.getHost() + ":" + toString(uri.getPort())))
{
throwUnacceptableURLException();
throw Exception("URL \"" + uri.toString() + "\" is not allowed in config.xml", ErrorCodes::UNACCEPTABLE_URL);
}
setColumns(columns_);
setConstraints(constraints_);
......@@ -248,26 +248,4 @@ bool IStorageURLBase::checkHost(const std::string & host)
}
return true;
}
void IStorageURLBase::throwUnacceptableURLException()
{
const std::unordered_set<std::string> primary_hosts = context_global.getAllowedPrimaryUrlHosts();
const std::vector<std::string> regexp_hosts = context_global.getAllowedRegexpUrlHosts();
std::string string_error = "Unacceptable URL. You can use ";
if (!primary_hosts.empty())
{
string_error += "URL like: ";
for (auto host : primary_hosts)
string_error += host + ", ";
if (!regexp_hosts.empty())
string_error += "or ";
}
if (!regexp_hosts.empty())
{
string_error += "URL that match the following regular expressions: ";
for (auto reg_host : regexp_hosts)
string_error += reg_host + ", ";
}
throw Exception(string_error.substr(0, string_error.size() - 2), ErrorCodes::UNACCEPTABLE_URL);
}
}
......@@ -67,9 +67,8 @@ private:
virtual Block getHeaderBlock(const Names & column_names) const = 0;
bool checkHost(const std::string & host); ///return true if host allowed
void throwUnacceptableURLException();
/// Return true if host allowed
bool checkHost(const std::string & host);
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册