feat: update response
This commit is contained in:
14
src/serve.rs
14
src/serve.rs
@@ -83,7 +83,9 @@ async fn response_requests(
|
||||
(&Method::POST, "/encrypt") => encrypt(req).await,
|
||||
(&Method::GET, "/status") => status().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) => (
|
||||
match $ex {
|
||||
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!({
|
||||
"error": "internal_error",
|
||||
"error_message": format!("{}", e),
|
||||
}))?.into())?),
|
||||
Err(e) => Ok(Response::builder().status(StatusCode::INTERNAL_SERVER_ERROR).body(
|
||||
format!("{}\n", serde_json::to_string_pretty(&json!({
|
||||
"error": "internal_error",
|
||||
"error_message": format!("{}", e),
|
||||
}))?).into()
|
||||
)?),
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user