mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-21 20:26:25 +00:00
simplify error handling
This commit is contained in:
@ -11,7 +11,7 @@ const UNHEALTHY_KEY: &str = "_is_unhealthy";
|
||||
|
||||
pub async fn get_health(ctx: Request<Data>) -> SResult<Response> {
|
||||
let db = &ctx.state().db;
|
||||
let reader = db.main_read_txn().map_err(ResponseError::internal)?;
|
||||
let reader = db.main_read_txn()?;
|
||||
|
||||
let common_store = ctx.state().db.common_store();
|
||||
|
||||
@ -24,38 +24,22 @@ pub async fn get_health(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
||||
pub async fn set_healthy(ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(Admin)?;
|
||||
|
||||
let db = &ctx.state().db;
|
||||
let mut writer = db.main_write_txn().map_err(ResponseError::internal)?;
|
||||
|
||||
let mut writer = db.main_write_txn()?;
|
||||
let common_store = ctx.state().db.common_store();
|
||||
match common_store.delete::<_, Str>(&mut writer, UNHEALTHY_KEY) {
|
||||
Ok(_) => (),
|
||||
Err(e) => return Err(ResponseError::internal(e)),
|
||||
}
|
||||
|
||||
if let Err(e) = writer.commit() {
|
||||
return Err(ResponseError::internal(e));
|
||||
}
|
||||
common_store.delete::<_, Str>(&mut writer, UNHEALTHY_KEY)?;
|
||||
writer.commit()?;
|
||||
|
||||
Ok(tide::Response::new(200))
|
||||
}
|
||||
|
||||
pub async fn set_unhealthy(ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(Admin)?;
|
||||
|
||||
let db = &ctx.state().db;
|
||||
let mut writer = db.main_write_txn().map_err(ResponseError::internal)?;
|
||||
|
||||
let mut writer = db.main_write_txn()?;
|
||||
let common_store = ctx.state().db.common_store();
|
||||
|
||||
if let Err(e) = common_store.put::<_, Str, Unit>(&mut writer, UNHEALTHY_KEY, &()) {
|
||||
return Err(ResponseError::internal(e));
|
||||
}
|
||||
|
||||
if let Err(e) = writer.commit() {
|
||||
return Err(ResponseError::internal(e));
|
||||
}
|
||||
common_store.put::<_, Str, Unit>(&mut writer, UNHEALTHY_KEY, &())?;
|
||||
writer.commit()?;
|
||||
|
||||
Ok(tide::Response::new(200))
|
||||
}
|
||||
|
Reference in New Issue
Block a user