404 returned when message list is 0
This commit is contained in:
parent
26fe2e722e
commit
0e93b12cbd
@ -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,13 +138,24 @@ pub async fn from_id(pool: &Pool, response: &mut Response<Body>, params: Value)
|
||||
Ok(db_response) => {
|
||||
match db_response {
|
||||
db::Response::Set(messages) => {
|
||||
// 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
|
||||
|
||||
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
|
||||
};
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user