aboutsummaryrefslogtreecommitdiff
path: root/src/api/admin/key.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-05-25 17:05:56 +0200
committerAlex Auvolat <alex@adnab.me>2022-05-25 17:09:33 +0200
commitff06d3f0829464863e64ed55471f2caa13bed191 (patch)
tree2ba08f439721c28d326badc0a33f148ee1fbdce1 /src/api/admin/key.rs
parent93eab8eaa3927b99626fee4a747a0f9f041cafdb (diff)
downloadgarage-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/key.rs')
-rw-r--r--src/api/admin/key.rs14
1 files changed, 3 insertions, 11 deletions
diff --git a/src/api/admin/key.rs b/src/api/admin/key.rs
index f30b5dbb..2bbabb7b 100644
--- a/src/api/admin/key.rs
+++ b/src/api/admin/key.rs
@@ -4,15 +4,13 @@ use std::sync::Arc;
use hyper::{Body, Request, Response, StatusCode};
use serde::{Deserialize, Serialize};
-use garage_util::error::Error as GarageError;
-
use garage_table::*;
use garage_model::garage::Garage;
use garage_model::key_table::*;
use crate::admin::error::*;
-use crate::helpers::parse_json_body;
+use crate::helpers::{json_ok_response, parse_json_body};
pub async fn handle_list_keys(garage: &Arc<Garage>) -> Result<Response<Body>, Error> {
let res = garage
@@ -32,10 +30,7 @@ pub async fn handle_list_keys(garage: &Arc<Garage>) -> Result<Response<Body>, Er
})
.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)?)
}
#[derive(Serialize)]
@@ -221,10 +216,7 @@ async fn key_info_results(garage: &Arc<Garage>, key: Key) -> Result<Response<Bod
.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)?)
}
#[derive(Serialize)]