Moved error handling to one function

This commit is contained in:
2024-04-29 13:40:31 +03:00
parent ff1d5a039d
commit 4ac34a73bb
12 changed files with 41 additions and 24 deletions

View File

@@ -1,3 +1,5 @@
use std::fmt::{Debug, Display};
#[derive(thiserror::Error, Debug)]
#[error("No user info found")]
pub struct NoUserInfo;
@@ -17,3 +19,24 @@ pub enum InvalidCommand {
#[error("Unknown locale passed into callback")]
UnknownLocale,
}
#[inline]
pub fn handle_error<T>(error: T)
where
T: Debug + Display,
{
log::error!("{error}\n{error:?}");
}
pub struct ErrorHandler;
impl teloxide::error_handlers::ErrorHandler<crate::Error> for ErrorHandler {
#[inline]
fn handle_error(
self: std::sync::Arc<Self>,
error: crate::Error,
) -> futures::prelude::future::BoxFuture<'static, ()> {
handle_error(error);
Box::pin(async {})
}
}