feat: update response
This commit is contained in:
10
src/serve.rs
10
src/serve.rs
@@ -83,7 +83,9 @@ async fn response_requests(
|
|||||||
(&Method::POST, "/encrypt") => encrypt(req).await,
|
(&Method::POST, "/encrypt") => encrypt(req).await,
|
||||||
(&Method::GET, "/status") => status().await,
|
(&Method::GET, "/status") => status().await,
|
||||||
(&Method::GET, "/version") => get_version().await,
|
(&Method::GET, "/version") => get_version().await,
|
||||||
_ => Ok(Response::builder().status(StatusCode::NOT_FOUND).body(serde_json::to_string_pretty(&json!({ "error": "not_found" }))?.into())?),
|
_ => Ok(Response::builder()
|
||||||
|
.status(StatusCode::NOT_FOUND)
|
||||||
|
.body(format!("{}\n", serde_json::to_string_pretty(&json!({ "error": "not_found" }))?).into())?),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,10 +93,12 @@ macro_rules! do_response {
|
|||||||
($ex: expr) => (
|
($ex: expr) => (
|
||||||
match $ex {
|
match $ex {
|
||||||
Ok((status_code, body)) => Ok(Response::builder().status(status_code).body(serde_json::to_string_pretty(&body)?.into())?),
|
Ok((status_code, body)) => Ok(Response::builder().status(status_code).body(serde_json::to_string_pretty(&body)?.into())?),
|
||||||
Err(e) => Ok(Response::builder().status(StatusCode::INTERNAL_SERVER_ERROR).body(serde_json::to_string_pretty(&json!({
|
Err(e) => Ok(Response::builder().status(StatusCode::INTERNAL_SERVER_ERROR).body(
|
||||||
|
format!("{}\n", serde_json::to_string_pretty(&json!({
|
||||||
"error": "internal_error",
|
"error": "internal_error",
|
||||||
"error_message": format!("{}", e),
|
"error_message": format!("{}", e),
|
||||||
}))?.into())?),
|
}))?).into()
|
||||||
|
)?),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user