Move MD logic in its own file
This commit is contained in:
@@ -195,30 +195,17 @@ void HttpServer::HandleGetLocalToken(const httplib::Request &req,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!db->ExtensionIsLoaded("motherduck")) {
|
|
||||||
res.set_content("", "text/plain"); // UI expects an empty response if the
|
|
||||||
// extension is not loaded
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Connection connection{*db};
|
Connection connection{*db};
|
||||||
try {
|
try {
|
||||||
auto token = GetMDToken(connection);
|
auto token = GetMDToken(connection);
|
||||||
res.status = 200;
|
res.status = 200;
|
||||||
res.set_content(token, "text/plain");
|
res.set_content(token, "text/plain");
|
||||||
} catch (std::exception &ex) {
|
} catch (std::exception &ex) {
|
||||||
if (StringUtil::Contains(
|
|
||||||
ex.what(), "GET_MD_TOKEN will be available after you connect")) {
|
|
||||||
// UI expects an empty response if MD isn't connected
|
|
||||||
res.status = 200;
|
|
||||||
res.set_content("", "text/plain");
|
|
||||||
} else {
|
|
||||||
res.status = 500;
|
res.status = 500;
|
||||||
res.set_content("Could not get token: " + std::string(ex.what()),
|
res.set_content("Could not get token: " + std::string(ex.what()),
|
||||||
"text/plain");
|
"text/plain");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void HttpServer::HandleGet(const httplib::Request &req,
|
void HttpServer::HandleGet(const httplib::Request &req,
|
||||||
httplib::Response &res) {
|
httplib::Response &res) {
|
||||||
|
|||||||
@@ -5,6 +5,10 @@
|
|||||||
|
|
||||||
namespace duckdb {
|
namespace duckdb {
|
||||||
std::string GetMDToken(Connection &connection) {
|
std::string GetMDToken(Connection &connection) {
|
||||||
|
if (!IsMDConnected(connection)) {
|
||||||
|
return ""; // UI expects an empty response if MD isn't connected
|
||||||
|
}
|
||||||
|
|
||||||
auto query_res = connection.Query("CALL GET_MD_TOKEN()");
|
auto query_res = connection.Query("CALL GET_MD_TOKEN()");
|
||||||
if (query_res->HasError()) {
|
if (query_res->HasError()) {
|
||||||
query_res->ThrowError();
|
query_res->ThrowError();
|
||||||
|
|||||||
Reference in New Issue
Block a user