0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-22 05:58:21 -05:00

Rename the error to NoSuchEngineFound and add the name of missing engine to it

This commit is contained in:
Zsombor Gegesy 2023-10-08 22:30:31 +02:00
parent 8ed4c9e206
commit f56002dca6
2 changed files with 10 additions and 6 deletions

View File

@ -85,14 +85,14 @@ impl EngineErrorInfo {
pub fn new(error: &EngineError, engine: &str) -> Self { pub fn new(error: &EngineError, engine: &str) -> Self {
Self { Self {
error: match error { error: match error {
EngineError::EngineNotFound => "EngineNotFound".to_owned(), EngineError::NoSuchEngineFound(_) => "EngineNotFound".to_owned(),
EngineError::RequestError => "RequestError".to_owned(), EngineError::RequestError => "RequestError".to_owned(),
EngineError::EmptyResultSet => "EmptyResultSet".to_owned(), EngineError::EmptyResultSet => "EmptyResultSet".to_owned(),
EngineError::UnexpectedError => "UnexpectedError".to_owned(), EngineError::UnexpectedError => "UnexpectedError".to_owned(),
}, },
engine: engine.to_owned(), engine: engine.to_owned(),
severity_color: match error { severity_color: match error {
EngineError::EngineNotFound => "red".to_owned(), EngineError::NoSuchEngineFound(_) => "red".to_owned(),
EngineError::RequestError => "green".to_owned(), EngineError::RequestError => "green".to_owned(),
EngineError::EmptyResultSet => "blue".to_owned(), EngineError::EmptyResultSet => "blue".to_owned(),
EngineError::UnexpectedError => "red".to_owned(), EngineError::UnexpectedError => "red".to_owned(),

View File

@ -9,7 +9,7 @@ use std::{collections::HashMap, fmt, time::Duration};
#[derive(Debug)] #[derive(Debug)]
pub enum EngineError { pub enum EngineError {
/// No matching engine found /// No matching engine found
EngineNotFound, NoSuchEngineFound(String),
/// This variant handles all request related errors like forbidden, not found, /// This variant handles all request related errors like forbidden, not found,
/// etc. /// etc.
EmptyResultSet, EmptyResultSet,
@ -26,8 +26,8 @@ pub enum EngineError {
impl fmt::Display for EngineError { impl fmt::Display for EngineError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
EngineError::EngineNotFound => { EngineError::NoSuchEngineFound(engine) => {
write!(f, "Search engine not found") write!(f, "No such engine with the name '{engine}' found")
} }
EngineError::EmptyResultSet => { EngineError::EmptyResultSet => {
write!(f, "The upstream search engine returned an empty result set") write!(f, "The upstream search engine returned an empty result set")
@ -150,7 +150,11 @@ impl EngineHandler {
let engine = crate::engines::searx::Searx::new()?; let engine = crate::engines::searx::Searx::new()?;
("searx", Box::new(engine)) ("searx", Box::new(engine))
} }
_ => return Err(Report::from(EngineError::EngineNotFound)), _ => {
return Err(Report::from(EngineError::NoSuchEngineFound(
engine_name.to_string(),
)))
}
}; };
Ok(Self { Ok(Self {