diff --git a/server-api/src/messages.rs b/server-api/src/messages.rs index d24344b..b906588 100644 --- a/server-api/src/messages.rs +++ b/server-api/src/messages.rs @@ -123,7 +123,7 @@ pub async fn from_id(pool: &Pool, response: &mut Response, 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, 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) => {