Moved error handling to one function
This commit is contained in:
@@ -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 {})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user