forked from gorb/backend
fix: remove more unwraps
found more unwraps that needed to be changed to ?
This commit is contained in:
parent
d8541b2eea
commit
1cda34d16b
6 changed files with 17 additions and 14 deletions
|
@ -59,14 +59,9 @@ pub async fn res(req: HttpRequest, data: web::Data<Data>) -> Result<HttpResponse
|
||||||
let current_time = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() as i64;
|
let current_time = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() as i64;
|
||||||
|
|
||||||
if lifetime > 1987200 {
|
if lifetime > 1987200 {
|
||||||
let new_refresh_token = generate_refresh_token();
|
let new_refresh_token = generate_refresh_token()?;
|
||||||
|
|
||||||
if new_refresh_token.is_err() {
|
let new_refresh_token = new_refresh_token;
|
||||||
error!("{}", new_refresh_token.unwrap_err());
|
|
||||||
return Ok(HttpResponse::InternalServerError().finish());
|
|
||||||
}
|
|
||||||
|
|
||||||
let new_refresh_token = new_refresh_token.unwrap();
|
|
||||||
|
|
||||||
match update(refresh_tokens::table)
|
match update(refresh_tokens::table)
|
||||||
.filter(rdsl::token.eq(&refresh_token))
|
.filter(rdsl::token.eq(&refresh_token))
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub async fn get(
|
||||||
|
|
||||||
let amount = request_query.amount.unwrap_or(10);
|
let amount = request_query.amount.unwrap_or(10);
|
||||||
|
|
||||||
check_access_token(auth_header, &mut data.pool.get().await.unwrap()).await?;
|
check_access_token(auth_header, &mut data.pool.get().await?).await?;
|
||||||
|
|
||||||
let guilds = Guild::fetch_amount(&data.pool, start, amount).await?;
|
let guilds = Guild::fetch_amount(&data.pool, start, amount).await?;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::v1::auth::check_access_token, error::Error, structs::{Channel, Member}, utils::{get_auth_header, order_channels}, Data
|
Data,
|
||||||
|
api::v1::auth::check_access_token,
|
||||||
|
error::Error,
|
||||||
|
structs::{Channel, Member},
|
||||||
|
utils::{get_auth_header, order_channels},
|
||||||
};
|
};
|
||||||
use ::uuid::Uuid;
|
use ::uuid::Uuid;
|
||||||
use actix_web::{HttpRequest, HttpResponse, get, post, web};
|
use actix_web::{HttpRequest, HttpResponse, get, post, web};
|
||||||
|
@ -41,8 +45,12 @@ pub async fn get(
|
||||||
|
|
||||||
let channels_ordered = order_channels(channels).await?;
|
let channels_ordered = order_channels(channels).await?;
|
||||||
|
|
||||||
data.set_cache_key(format!("{}_channels", guild_uuid), channels_ordered.clone(), 1800)
|
data.set_cache_key(
|
||||||
.await?;
|
format!("{}_channels", guild_uuid),
|
||||||
|
channels_ordered.clone(),
|
||||||
|
1800,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(channels_ordered))
|
Ok(HttpResponse::Ok().json(channels_ordered))
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ pub async fn delete(
|
||||||
let channel: Channel;
|
let channel: Channel;
|
||||||
|
|
||||||
if let Ok(cache_hit) = data.get_cache_key(format!("{}", channel_uuid)).await {
|
if let Ok(cache_hit) = data.get_cache_key(format!("{}", channel_uuid)).await {
|
||||||
channel = serde_json::from_str(&cache_hit).unwrap();
|
channel = serde_json::from_str(&cache_hit)?;
|
||||||
|
|
||||||
data.del_cache_key(format!("{}", channel_uuid)).await?;
|
data.del_cache_key(format!("{}", channel_uuid)).await?;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -42,7 +42,7 @@ pub async fn echo(
|
||||||
|
|
||||||
// Return channel cache or result from psql as `channel` variable
|
// Return channel cache or result from psql as `channel` variable
|
||||||
if let Ok(cache_hit) = data.get_cache_key(format!("{}", channel_uuid)).await {
|
if let Ok(cache_hit) = data.get_cache_key(format!("{}", channel_uuid)).await {
|
||||||
channel = serde_json::from_str(&cache_hit).unwrap()
|
channel = serde_json::from_str(&cache_hit)?
|
||||||
} else {
|
} else {
|
||||||
channel = Channel::fetch_one(&mut conn, channel_uuid).await?;
|
channel = Channel::fetch_one(&mut conn, channel_uuid).await?;
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ pub async fn create(
|
||||||
|
|
||||||
let guild_uuid = path.into_inner().0;
|
let guild_uuid = path.into_inner().0;
|
||||||
|
|
||||||
let mut conn = data.pool.get().await.unwrap();
|
let mut conn = data.pool.get().await?;
|
||||||
|
|
||||||
let uuid = check_access_token(auth_header, &mut conn).await?;
|
let uuid = check_access_token(auth_header, &mut conn).await?;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue