fix: don't interrupt login if error getting character info

This commit is contained in:
Anna 2022-08-13 09:56:44 -04:00
parent 12741c0c33
commit e0683e1036
1 changed files with 23 additions and 16 deletions

View File

@ -4,7 +4,7 @@ use std::sync::Arc;
use anyhow::Context;
use chrono::{Duration, Utc};
use lodestone_scraper::LodestoneScraper;
use log::trace;
use log::{trace, warn};
use tokio::sync::RwLock;
use crate::{AuthenticateRequest, AuthenticateResponse, ClientState, State, User, util, World, WsStream};
@ -34,8 +34,10 @@ pub async fn authenticate(state: Arc<RwLock<State>>, client_state: Arc<RwLock<Cl
if Utc::now().naive_utc().signed_duration_since(user.last_updated) >= Duration::hours(2) {
let info = LodestoneScraper::default()
.character(user.lodestone_id as u64)
.await
.context("could not get character info")?;
.await;
match info {
Ok(info) => {
let world_name = info.world.as_str();
user.name = info.name.clone();
@ -52,6 +54,11 @@ pub async fn authenticate(state: Arc<RwLock<State>>, client_state: Arc<RwLock<Cl
.await
.context("could not update user")?;
}
Err(e) => {
warn!("could not get character info during login: {:#?}", e);
}
}
}
let world = World::from_str(&user.world).map_err(|_| anyhow::anyhow!("invalid world in db"))?;