diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/controller.cpp | 2 | ||||
-rw-r--r-- | src/minifluxapi.cpp | 13 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/controller.cpp b/src/controller.cpp index 2bce8c36..e79f29b0 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -381,7 +381,7 @@ int Controller::run(const CliArgsParser& args) } if (api) { if (!api->authenticate()) { - std::cout << "Authentication failed." << std::endl; + std::cerr << _("Authentication failed.") << std::endl; return EXIT_FAILURE; } } diff --git a/src/minifluxapi.cpp b/src/minifluxapi.cpp index 4b581dc6..b114c639 100644 --- a/src/minifluxapi.cpp +++ b/src/minifluxapi.cpp @@ -2,9 +2,11 @@ #include <cinttypes> #include <curl/curl.h> +#include <iostream> #include <thread> #include "3rd-party/json.hpp" +#include "config.h" #include "curlhandle.h" #include "logger.h" #include "remoteapi.h" @@ -43,12 +45,21 @@ bool MinifluxApi::authenticate() CurlHandle handle; long response_code = 0; - run_op("/v1/me", json(), handle); + const std::string path = "/v1/me"; + run_op(path, json(), handle); curl_easy_getinfo(handle.ptr(), CURLINFO_RESPONSE_CODE, &response_code); if (response_code == 401) { return false; } + if (response_code < 200 || response_code > 299) { + const auto url = server + path; + std::cerr << strprintf::fmt( + _("Authentication check using %s failed (HTTP response code: %s)"), + url, + std::to_string(response_code)) << std::endl; + return false; + } return true; } |