summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rust/libnewsboat/src/human_panic.rs9
-rw-r--r--src/controller.cpp2
-rw-r--r--src/minifluxapi.cpp13
3 files changed, 21 insertions, 3 deletions
diff --git a/rust/libnewsboat/src/human_panic.rs b/rust/libnewsboat/src/human_panic.rs
index 559a4a81..1c54cd9c 100644
--- a/rust/libnewsboat/src/human_panic.rs
+++ b/rust/libnewsboat/src/human_panic.rs
@@ -69,19 +69,24 @@
//! beginning of the program.
use backtrace::Backtrace;
use std::io::{self, stderr, BufWriter, Write};
-use std::panic::{self, PanicInfo};
+use std::panic;
+
+#[allow(deprecated)] // Change to PanicHookInfo when our MSRV has increased to 1.81.0 or later
+use std::panic::PanicInfo;
/// Sets up a panic hook with a user-friendly message.
///
/// See module description for details.
pub fn setup() {
if ::std::env::var("RUST_BACKTRACE").is_err() {
+ #[allow(deprecated)]
panic::set_hook(Box::new(move |panic_info: &PanicInfo| {
print_panic_msg(panic_info).expect("An error occurred while preparing a crash report");
}));
}
}
+#[allow(deprecated)]
fn print_panic_msg(panic_info: &PanicInfo) -> io::Result<()> {
// Locking the handle to make sure all the messages are printed out in one chunk.
let stderr = stderr();
@@ -125,6 +130,7 @@ fn print_panic_msg(panic_info: &PanicInfo) -> io::Result<()> {
Ok(())
}
+#[allow(deprecated)]
fn get_error_message(panic_info: &PanicInfo) -> String {
let payload = panic_info.payload().downcast_ref::<&str>();
if let Some(payload) = payload {
@@ -134,6 +140,7 @@ fn get_error_message(panic_info: &PanicInfo) -> String {
}
}
+#[allow(deprecated)]
fn get_location(panic_info: &PanicInfo) -> String {
match panic_info.location() {
Some(location) => format!("Crash location: {}:{}", location.file(), location.line()),
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;
}