* /message/recent no longer uses unwraps

This should make it way safer
This commit is contained in:
shockrah 2021-05-29 14:23:47 -07:00
parent 32dbbe11eb
commit 4c0888a263
2 changed files with 7 additions and 2 deletions

3
json-api/.gitignore vendored
View File

@ -10,3 +10,6 @@ diesel.toml
# Client pycache
client-tests/__pycache__/
client-tests/web/__pycache__/
# Admin things
msg

View File

@ -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;
}
}