From afdeef0a497d98e14955b2fb405b40ffc1f5a1f4 Mon Sep 17 00:00:00 2001 From: shockrah Date: Tue, 30 Mar 2021 23:00:50 -0700 Subject: [PATCH] More warning removals and more db-lib result wrapping This should be everything now --- json-api/db/src/channels.rs | 9 +++------ json-api/src/channels.rs | 2 ++ json-api/src/invites.rs | 10 ++++++++-- json-api/src/main.rs | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/json-api/db/src/channels.rs b/json-api/db/src/channels.rs index 961eaf4..b292aa1 100644 --- a/json-api/db/src/channels.rs +++ b/json-api/db/src/channels.rs @@ -3,7 +3,7 @@ use mysql_async::prelude::Queryable; use mysql_async::Error as SqlError; use crate::{Channel, UBigInt, Integer}; -use crate::{sql_err, Response}; +use crate::Response; use rand::RngCore; @@ -75,11 +75,8 @@ impl Channel { let mut conn = p.get_conn().await?; let q = "DELETE FROM channels WHERE id = :id"; - let result = conn.exec_drop(q, params!{"id" => id}).await; - return match result { - Ok(_) => Ok(Response::Success), - Err(sql) => Ok(Response::Other(sql_err!(sql))) - } + conn.exec_drop(q, params!{"id" => id}).await?; + Ok(Response::Success) } diff --git a/json-api/src/channels.rs b/json-api/src/channels.rs index ed90ba3..29ab0b5 100644 --- a/json-api/src/channels.rs +++ b/json-api/src/channels.rs @@ -86,6 +86,7 @@ pub async fn delete_channel(pool: &Pool, response: &mut Response, params: let uid = qs_param!(params, "id", u64).unwrap(); let permissions = match Member::get(pool, uid).await { Ok(Row(user)) => user.permissions, + Ok(_) => 0, Err(e) => { eprintln!("{}", e); 0 @@ -112,6 +113,7 @@ pub async fn delete_channel(pool: &Pool, response: &mut Response, params: if let Some(id) = channel_id { match Channel::delete(pool, id).await { Ok(Success) => {/* nothing to do on sucess */}, + Ok(_) => {/* can't actually happen */} Err(e) => { // ngmi eprintln!("{}", e); *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; diff --git a/json-api/src/invites.rs b/json-api/src/invites.rs index d73485a..77cc938 100644 --- a/json-api/src/invites.rs +++ b/json-api/src/invites.rs @@ -121,8 +121,14 @@ async fn allowed_perm_invite(pool: &Pool, uid: u64) -> bool { use crate::perms; return match Member::get(pool, uid).await { - db::Response::Row(user) => perms::has_perm(user.permissions, perms::CREATE_PERM_INVITES), - _ => false + Ok(response) => match response { + db::Response::Row(user) => perms::has_perm(user.permissions, perms::CREATE_PERM_INVITES), + _ => false + }, + Err(e) => { + eprintln!("[HTTP-DB-ERROR] {}", e); + false + } }; } pub async fn create(pool: &Pool, response: &mut Response, params: HashMap) { diff --git a/json-api/src/main.rs b/json-api/src/main.rs index 0f23570..988713c 100644 --- a/json-api/src/main.rs +++ b/json-api/src/main.rs @@ -190,7 +190,7 @@ async fn attempt_owner_creation(name: &str) { else { eprintln!("Could not generate a proper secret"); } - p.disconnect(); + let _ = p.disconnect().await; } #[tokio::main]