* /message/recent no longer uses unwraps
This should make it way safer
This commit is contained in:
parent
32dbbe11eb
commit
4c0888a263
3
json-api/.gitignore
vendored
3
json-api/.gitignore
vendored
@ -10,3 +10,6 @@ diesel.toml
|
||||
# Client pycache
|
||||
client-tests/__pycache__/
|
||||
client-tests/web/__pycache__/
|
||||
|
||||
# Admin things
|
||||
msg
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user