diff --git a/src/launchpad.cpp b/src/launchpad.cpp index 4c540d9..33e9857 100644 --- a/src/launchpad.cpp +++ b/src/launchpad.cpp @@ -211,12 +211,16 @@ bool launchpad::is_authenticated() const { std::string launchpad::build_full_url(const std::string& endpoint) const { if (endpoint.rfind("http", 0) == 0) { return endpoint; + } else if (endpoint != "") { + return service_root + "/" + api_version + "/" + endpoint; } - return service_root + "/" + api_version + "/" + endpoint; + std::cerr << "endpoint is empty" << std::endl; + return ""; } std::optional launchpad::api_get(const std::string& endpoint, const std::map& params) const { std::string url = build_full_url(endpoint); + if (url.empty()) { return std::nullopt; } if (!params.empty()) { url += "?"; for (const auto& [key, value] : params) { @@ -282,6 +286,7 @@ std::optional launchpad::api_post( const std::string& token_secret_override ) { std::string url = build_endpoint ? build_full_url(endpoint) : endpoint; + if (url.empty()) { return std::nullopt; } CURL* curl = curl_easy_init(); if (!curl) { @@ -346,6 +351,7 @@ std::optional launchpad::api_post( std::optional launchpad::api_patch(const std::string& endpoint, const nlohmann::json& data) { std::string url = build_full_url(endpoint) + "?ws.op=edit"; + if (url.empty()) { return std::nullopt; } CURL* curl = curl_easy_init(); if (!curl) { std::cerr << "Failed to initialize CURL for PATCH request." << std::endl; @@ -399,6 +405,7 @@ std::optional launchpad::api_patch(const std::string& endpoint, con std::optional launchpad::api_delete(const std::string& endpoint) { // We'll try DELETE method: std::string url = build_full_url(endpoint); + if (url.empty()) { return std::nullopt; } CURL* curl = curl_easy_init(); if (!curl) { std::cerr << "Failed to initialize CURL for DELETE request." << std::endl;