refactor: resultify token::lookup_or_new()

This commit is contained in:
link2xt
2024-05-14 18:14:03 +00:00
parent c349bf8e0c
commit 07ceabdf85
2 changed files with 7 additions and 7 deletions

View File

@@ -93,14 +93,14 @@ pub async fn lookup_or_new(
context: &Context,
namespace: Namespace,
foreign_id: Option<ChatId>,
) -> String {
if let Ok(Some(token)) = lookup(context, namespace, foreign_id).await {
return token;
) -> Result<String> {
if let Some(token) = lookup(context, namespace, foreign_id).await? {
return Ok(token);
}
let token = create_id();
save(context, namespace, foreign_id, &token).await.ok();
token
save(context, namespace, foreign_id, &token).await?;
Ok(token)
}
pub async fn exists(context: &Context, namespace: Namespace, token: &str) -> Result<bool> {