mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-21 21:48:21 -05:00
Rename the error to NoSuchEngineFound and add the name of missing engine to it
This commit is contained in:
parent
8ed4c9e206
commit
f56002dca6
@ -85,14 +85,14 @@ impl EngineErrorInfo {
|
||||
pub fn new(error: &EngineError, engine: &str) -> Self {
|
||||
Self {
|
||||
error: match error {
|
||||
EngineError::EngineNotFound => "EngineNotFound".to_owned(),
|
||||
EngineError::NoSuchEngineFound(_) => "EngineNotFound".to_owned(),
|
||||
EngineError::RequestError => "RequestError".to_owned(),
|
||||
EngineError::EmptyResultSet => "EmptyResultSet".to_owned(),
|
||||
EngineError::UnexpectedError => "UnexpectedError".to_owned(),
|
||||
},
|
||||
engine: engine.to_owned(),
|
||||
severity_color: match error {
|
||||
EngineError::EngineNotFound => "red".to_owned(),
|
||||
EngineError::NoSuchEngineFound(_) => "red".to_owned(),
|
||||
EngineError::RequestError => "green".to_owned(),
|
||||
EngineError::EmptyResultSet => "blue".to_owned(),
|
||||
EngineError::UnexpectedError => "red".to_owned(),
|
||||
|
@ -9,7 +9,7 @@ use std::{collections::HashMap, fmt, time::Duration};
|
||||
#[derive(Debug)]
|
||||
pub enum EngineError {
|
||||
/// No matching engine found
|
||||
EngineNotFound,
|
||||
NoSuchEngineFound(String),
|
||||
/// This variant handles all request related errors like forbidden, not found,
|
||||
/// etc.
|
||||
EmptyResultSet,
|
||||
@ -26,8 +26,8 @@ pub enum EngineError {
|
||||
impl fmt::Display for EngineError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
EngineError::EngineNotFound => {
|
||||
write!(f, "Search engine not found")
|
||||
EngineError::NoSuchEngineFound(engine) => {
|
||||
write!(f, "No such engine with the name '{engine}' found")
|
||||
}
|
||||
EngineError::EmptyResultSet => {
|
||||
write!(f, "The upstream search engine returned an empty result set")
|
||||
@ -150,7 +150,11 @@ impl EngineHandler {
|
||||
let engine = crate::engines::searx::Searx::new()?;
|
||||
("searx", Box::new(engine))
|
||||
}
|
||||
_ => return Err(Report::from(EngineError::EngineNotFound)),
|
||||
_ => {
|
||||
return Err(Report::from(EngineError::NoSuchEngineFound(
|
||||
engine_name.to_string(),
|
||||
)))
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
|
Loading…
Reference in New Issue
Block a user