diff options
author | Alex Auvolat <alex@adnab.me> | 2022-05-25 17:05:56 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-05-25 17:09:33 +0200 |
commit | ff06d3f0829464863e64ed55471f2caa13bed191 (patch) | |
tree | 2ba08f439721c28d326badc0a33f148ee1fbdce1 /src/api/admin/cluster.rs | |
parent | 93eab8eaa3927b99626fee4a747a0f9f041cafdb (diff) | |
download | garage-ff06d3f0829464863e64ed55471f2caa13bed191.tar.gz garage-ff06d3f0829464863e64ed55471f2caa13bed191.zip |
Fix Content-Type headers for {admin,k2v} errors and admin responsesfix/admin-api-content-type
Fix #315
Diffstat (limited to 'src/api/admin/cluster.rs')
-rw-r--r-- | src/api/admin/cluster.rs | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/src/api/admin/cluster.rs b/src/api/admin/cluster.rs index 3401be42..6d01317d 100644 --- a/src/api/admin/cluster.rs +++ b/src/api/admin/cluster.rs @@ -7,14 +7,13 @@ use serde::{Deserialize, Serialize}; use garage_util::crdt::*; use garage_util::data::*; -use garage_util::error::Error as GarageError; use garage_rpc::layout::*; use garage_model::garage::Garage; use crate::admin::error::*; -use crate::helpers::parse_json_body; +use crate::helpers::{json_ok_response, parse_json_body}; pub async fn handle_get_cluster_status(garage: &Arc<Garage>) -> Result<Response<Body>, Error> { let res = GetClusterStatusResponse { @@ -39,10 +38,7 @@ pub async fn handle_get_cluster_status(garage: &Arc<Garage>) -> Result<Response< layout: get_cluster_layout(garage), }; - let resp_json = serde_json::to_string_pretty(&res).map_err(GarageError::from)?; - Ok(Response::builder() - .status(StatusCode::OK) - .body(Body::from(resp_json))?) + Ok(json_ok_response(&res)?) } pub async fn handle_connect_cluster_nodes( @@ -66,18 +62,13 @@ pub async fn handle_connect_cluster_nodes( }) .collect::<Vec<_>>(); - let resp_json = serde_json::to_string_pretty(&res).map_err(GarageError::from)?; - Ok(Response::builder() - .status(StatusCode::OK) - .body(Body::from(resp_json))?) + Ok(json_ok_response(&res)?) } pub async fn handle_get_cluster_layout(garage: &Arc<Garage>) -> Result<Response<Body>, Error> { let res = get_cluster_layout(garage); - let resp_json = serde_json::to_string_pretty(&res).map_err(GarageError::from)?; - Ok(Response::builder() - .status(StatusCode::OK) - .body(Body::from(resp_json))?) + + Ok(json_ok_response(&res)?) } fn get_cluster_layout(garage: &Arc<Garage>) -> GetClusterLayoutResponse { |