52 lines
1.5 KiB
Rust
52 lines
1.5 KiB
Rust
use std::fmt::{Debug, Display};
|
|
use tracing_subscriber::{EnvFilter, fmt, prelude::*};
|
|
|
|
#[derive(derive_more::Error, derive_more::Display, Debug)]
|
|
#[display("No user info found")]
|
|
pub struct NoUserInfo;
|
|
|
|
#[derive(derive_more::Error, derive_more::Display, Debug)]
|
|
#[display("Handler was already used")]
|
|
pub struct HandlerUsed;
|
|
|
|
#[derive(derive_more::Error, derive_more::Display, derive_more::From, Debug)]
|
|
pub enum InvalidCommand {
|
|
#[display("Invalid params")]
|
|
InvalidParams,
|
|
#[display("Not enough bytes in the name's hash")]
|
|
InvalidOutputLength,
|
|
#[display("Error decoding the values: {}", 0)]
|
|
NameDecodingError(base64::DecodeError),
|
|
#[display("Unknown locale passed into callback")]
|
|
UnknownLocale,
|
|
}
|
|
|
|
pub fn init_logger() {
|
|
tracing_subscriber::registry()
|
|
.with(fmt::layer().pretty())
|
|
.with(EnvFilter::from_default_env())
|
|
.init();
|
|
}
|
|
|
|
/// Handles an error.
|
|
/// This function must be as cheap and generic as possible and must remain sync.
|
|
/// If expensive or long action is required, a task should be spawned but not joined.
|
|
pub fn handle_error<T>(error: T)
|
|
where
|
|
T: Debug + Display,
|
|
{
|
|
tracing::error!(error_debug = ?error, error_message = %error);
|
|
}
|
|
|
|
pub struct ErrorHandler;
|
|
|
|
impl teloxide::error_handlers::ErrorHandler<crate::Error> for ErrorHandler {
|
|
fn handle_error(
|
|
self: std::sync::Arc<Self>,
|
|
error: crate::Error,
|
|
) -> futures::prelude::future::BoxFuture<'static, ()> {
|
|
handle_error(error);
|
|
Box::pin(async {})
|
|
}
|
|
}
|