404 returned when message list is 0

This commit is contained in:
shockrah 2021-01-23 14:23:20 -08:00
parent 26fe2e722e
commit 0e93b12cbd

View File

@ -123,7 +123,7 @@ pub async fn from_id(pool: &Pool, response: &mut Response<Body>, params: Value)
Some(chan_v) => chan_v.as_u64(),
None => None
};
let start_id = match params.get("start-id") {
let start_id = match params.get("start") {
Some(val) => val.as_u64(),
None => None
};
@ -138,14 +138,25 @@ pub async fn from_id(pool: &Pool, response: &mut Response<Body>, params: Value)
Ok(db_response) => {
match db_response {
db::Response::Set(messages) => {
response.headers_mut().insert(
"Content-Type",
HeaderValue::from_static("application/json"));
// NOTE: we do this in the api layer because the db's
// lead this to not be defined behavior
// if a length is _actually_ 0 the check fails
// also hot caches rek us pretty hard so that doesn't help either
let payload = json!({"messages": messages});
*response.body_mut() = Body::from(payload.to_string());
if messages.len() == 0 {
*response.status_mut() = StatusCode::NOT_FOUND;
}
else {
response.headers_mut().insert(
"Content-Type",
HeaderValue::from_static("application/json"));
let payload = json!({"messages": messages});
*response.body_mut() = Body::from(payload.to_string());
}
},
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
};
},
Err(err) => {