* /message/recent no longer uses unwraps
This should make it way safer
This commit is contained in:
@@ -125,9 +125,10 @@ pub async fn recent_messages(pool: &Pool, response: &mut Response<Body>, params:
|
||||
let limit = qs_param!(params, "limit", i32);
|
||||
let channel_id = qs_param!(params, "channel_id", u64);
|
||||
|
||||
if channel_id.is_some() && limit.is_some() {
|
||||
if let (Some(channel_id), Some(limit)) = (channel_id, limit) {
|
||||
println!("channel_id: {}", channel_id);
|
||||
// NOTE: using match here to capture+log the error from the database
|
||||
match Message::last_n(pool, limit.unwrap(), channel_id.unwrap()).await {
|
||||
match Message::last_n(pool, limit, channel_id).await {
|
||||
Ok(dbresp) => {
|
||||
match dbresp {
|
||||
// 200
|
||||
@@ -150,6 +151,7 @@ pub async fn recent_messages(pool: &Pool, response: &mut Response<Body>, params:
|
||||
}
|
||||
}
|
||||
} else {
|
||||
*response.status_mut() = StatusCode::BAD_REQUEST;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user