From ce51a080eed1768c894274640a4fb88e3b5fa478 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 2 Jan 2024 11:35:06 +0000 Subject: [PATCH] Make AuthError into a subcase of ClientError. Now tui.rs doesn't have to handle it directly, and our client setup can return the more general ClientError. --- src/auth.rs | 2 +- src/client.rs | 9 ++++++++- src/tui.rs | 8 -------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/auth.rs b/src/auth.rs index ce195d9..2983e1c 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use super::config::ConfigLocation; -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq, Clone)] pub enum AuthError { Nonexistent(String), Bad(String), diff --git a/src/client.rs b/src/client.rs index 66a32ef..7c0df5b 100644 --- a/src/client.rs +++ b/src/client.rs @@ -60,11 +60,16 @@ pub struct Client { #[derive(Debug, PartialEq, Eq, Clone)] pub enum ClientError { + Auth(AuthError), // message InternalError(String), // message UrlParseError(String, String), // url, message UrlError(String, String), // url, message } +impl From for ClientError { + fn from(err: AuthError) -> Self { ClientError::Auth(err) } +} + impl From for ClientError { fn from(err: reqwest::Error) -> Self { match err.url() { @@ -80,6 +85,8 @@ impl std::fmt::Display for ClientError { Result<(), std::fmt::Error> { match self { + ClientError::Auth(ref autherr) => + write!(f, "unable to read authentication: {}", autherr), ClientError::InternalError(ref msg) => write!(f, "internal failure: {}", msg), ClientError::UrlParseError(ref url, ref msg) => @@ -152,7 +159,7 @@ pub enum FeedExtend { } impl Client { - pub fn new(cfgloc: &ConfigLocation) -> Result { + pub fn new(cfgloc: &ConfigLocation) -> Result { Ok(Client { auth: AuthConfig::load(cfgloc)?, client: reqwest::blocking::Client::new(), diff --git a/src/tui.rs b/src/tui.rs index 70c55cc..af0fa27 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -22,7 +22,6 @@ use super::config::ConfigLocation; use super::menu::*; use super::file::*; use super::editor::*; -use super::auth::AuthError; fn ratatui_style_from_colour(colour: char) -> Style { match colour { @@ -171,13 +170,6 @@ impl From for TuiError { } } } -impl From for TuiError { - fn from(err: AuthError) -> Self { - TuiError { - message: format!("unable to read authentication: {}", err), - } - } -} impl From for TuiError { fn from(err: ClientError) -> Self { TuiError { -- 2.30.2