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(),
|
Some(chan_v) => chan_v.as_u64(),
|
||||||
None => None
|
None => None
|
||||||
};
|
};
|
||||||
let start_id = match params.get("start-id") {
|
let start_id = match params.get("start") {
|
||||||
Some(val) => val.as_u64(),
|
Some(val) => val.as_u64(),
|
||||||
None => None
|
None => None
|
||||||
};
|
};
|
||||||
@ -138,14 +138,25 @@ pub async fn from_id(pool: &Pool, response: &mut Response<Body>, params: Value)
|
|||||||
Ok(db_response) => {
|
Ok(db_response) => {
|
||||||
match db_response {
|
match db_response {
|
||||||
db::Response::Set(messages) => {
|
db::Response::Set(messages) => {
|
||||||
response.headers_mut().insert(
|
// NOTE: we do this in the api layer because the db's
|
||||||
"Content-Type",
|
// lead this to not be defined behavior
|
||||||
HeaderValue::from_static("application/json"));
|
// 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});
|
if messages.len() == 0 {
|
||||||
*response.body_mut() = Body::from(payload.to_string());
|
*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) => {
|
Err(err) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user