Updated get_accounts to handle the errors of concatenating the accounts

This commit is contained in:
StNicolay 2023-06-05 10:57:47 +03:00
parent 9d0fa17a0e
commit f74d34f188
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D

View File

@ -1,6 +1,6 @@
use crate::{errors::NoUserInfo, markups::deletion_markup};
use entity::prelude::*;
use futures::TryStreamExt;
use futures::{future, TryStreamExt};
use sea_orm::DatabaseConnection;
use std::fmt::Write;
use teloxide::{adaptors::Throttle, prelude::*, types::ParseMode};
@ -13,7 +13,7 @@ pub async fn get_accounts(
) -> crate::Result<()> {
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
let mut account_names = Account::get_names(user_id, &db, true).await?;
let mut result = match account_names.try_next().await? {
let mut text = match account_names.try_next().await? {
Some(name) => format!("Accounts:\n`{name}`"),
None => {
bot.send_message(msg.chat.id, "No accounts found")
@ -23,12 +23,13 @@ pub async fn get_accounts(
}
};
account_names
.map_err(crate::Error::from)
.try_for_each(|name| {
write!(result, "\n`{name}`").unwrap();
async { Ok(()) }
let result = write!(text, "\n`{name}`").map_err(Into::into);
future::ready(result)
})
.await?;
bot.send_message(msg.chat.id, result)
bot.send_message(msg.chat.id, text)
.parse_mode(ParseMode::MarkdownV2)
.reply_markup(deletion_markup())
.await?;