use crate::common::error::CrawlRsError;
use std::fmt::Display;
pub fn map_to_other_error<E: Display>(error: E) -> CrawlRsError {
CrawlRsError::Other(error.to_string())
}
#[cfg(feature = "platform")]
pub fn map_to_database_error<E: Display>(error: E) -> CrawlRsError {
CrawlRsError::Database(dbnexus::sea_orm::DbErr::Custom(error.to_string()))
}
pub fn map_to_network_error<E: Display>(error: E) -> CrawlRsError {
CrawlRsError::Network(error.to_string())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_map_to_other_error() {
let error = map_to_other_error("test error");
assert!(matches!(error, CrawlRsError::Other(_)));
}
#[test]
#[cfg(feature = "platform")]
fn test_map_to_database_error() {
let error = map_to_database_error("db error");
assert!(matches!(error, CrawlRsError::Database(_)));
}
#[test]
fn test_map_to_network_error() {
let error = map_to_network_error("network failure");
assert!(matches!(error, CrawlRsError::Network(_)));
}
}