Updated master_password_check to use Arc<dyn Error> instead of a string representation of an error
This commit is contained in:
parent
cda07b4d84
commit
a817f7f39c
@ -1,35 +1,38 @@
|
|||||||
use crate::errors::NoUserInfo;
|
use crate::errors::NoUserInfo;
|
||||||
|
use crate::markups::deletion_markup;
|
||||||
use entity::prelude::*;
|
use entity::prelude::*;
|
||||||
use sea_orm::DatabaseConnection;
|
use sea_orm::DatabaseConnection;
|
||||||
|
use std::sync::Arc;
|
||||||
use teloxide::{adaptors::Throttle, dispatching::DpHandlerDescription, prelude::*};
|
use teloxide::{adaptors::Throttle, dispatching::DpHandlerDescription, prelude::*};
|
||||||
|
|
||||||
use super::markups::deletion_markup;
|
|
||||||
|
|
||||||
/// A wierd filter that checks for the existance of a master password.
|
/// A wierd filter that checks for the existance of a master password.
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// Returns None if account exists, Some(None) if there's an account and Some(Some(String)) if an error occures.
|
/// Returns None if account exists, Some(None) if there's an account and Some(Some(String)) if an error occures.
|
||||||
/// The String represents the error that occured
|
/// The String represents the error that occured
|
||||||
async fn master_pass_exists(msg: Message, db: DatabaseConnection) -> Option<Option<String>> {
|
async fn master_pass_exists(
|
||||||
|
msg: Message,
|
||||||
|
db: DatabaseConnection,
|
||||||
|
) -> Option<Option<Arc<dyn std::error::Error + Send + Sync>>> {
|
||||||
let user_id = match msg.from() {
|
let user_id = match msg.from() {
|
||||||
Some(user) => user.id.0,
|
Some(user) => user.id.0,
|
||||||
None => return Some(Some(NoUserInfo.to_string())),
|
None => return Some(Some(Arc::new(NoUserInfo))),
|
||||||
};
|
};
|
||||||
match MasterPass::exists(user_id, &db).await {
|
match MasterPass::exists(user_id, &db).await {
|
||||||
Ok(true) => None,
|
Ok(true) => None,
|
||||||
Ok(false) => Some(None),
|
Ok(false) => Some(None),
|
||||||
Err(err) => Some(Some(err.to_string())),
|
Err(err) => Some(Some(Arc::new(err))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn notify_about_no_master_pass(
|
async fn notify_about_no_master_pass(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
result: Option<String>,
|
result: Option<Arc<dyn std::error::Error + Send + Sync>>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
if let Some(message) = result {
|
if let Some(error) = result {
|
||||||
return Err(crate::Error::msg(message));
|
return Err(error.into());
|
||||||
}
|
}
|
||||||
bot.send_message(msg.chat.id, "No master password set")
|
bot.send_message(msg.chat.id, "No master password set")
|
||||||
.reply_markup(deletion_markup())
|
.reply_markup(deletion_markup())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user