Return http code instead of plain error
This commit is contained in:
+1
-1
@@ -263,7 +263,7 @@ async fn binned(req: Request<Body>, node_config: &NodeConfigCached) -> Result<Re
|
|||||||
match head.headers.get("accept") {
|
match head.headers.get("accept") {
|
||||||
Some(v) if v == "application/octet-stream" => binned_binary(query, node_config).await,
|
Some(v) if v == "application/octet-stream" => binned_binary(query, node_config).await,
|
||||||
Some(v) if v == "application/json" => binned_json(query, node_config).await,
|
Some(v) if v == "application/json" => binned_json(query, node_config).await,
|
||||||
_ => Err(Error::with_msg("binned with unknown accept")),
|
_ => Ok(response(StatusCode::NOT_ACCEPTABLE).body(Body::empty())?),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-5
@@ -1,12 +1,18 @@
|
|||||||
|
use crate::response;
|
||||||
use err::Error;
|
use err::Error;
|
||||||
use hyper::{Body, Request, Response, StatusCode};
|
use hyper::{Body, Request, Response, StatusCode};
|
||||||
use netpod::{ChannelSearchQuery, NodeConfigCached};
|
use netpod::{ChannelSearchQuery, NodeConfigCached};
|
||||||
|
|
||||||
pub async fn channel_search(req: Request<Body>, node_config: &NodeConfigCached) -> Result<Response<Body>, Error> {
|
pub async fn channel_search(req: Request<Body>, node_config: &NodeConfigCached) -> Result<Response<Body>, Error> {
|
||||||
let (head, _body) = req.into_parts();
|
let (head, _body) = req.into_parts();
|
||||||
let query = ChannelSearchQuery::from_request(head.uri.query())?;
|
match head.headers.get("accept") {
|
||||||
let res = dbconn::search::search_channel(query, node_config).await?;
|
Some(v) if v == "application/json" => {
|
||||||
let body = Body::from(serde_json::to_string(&res)?);
|
let query = ChannelSearchQuery::from_request(head.uri.query())?;
|
||||||
let ret = super::response(StatusCode::OK).body(body)?;
|
let res = dbconn::search::search_channel(query, node_config).await?;
|
||||||
Ok(ret)
|
let body = Body::from(serde_json::to_string(&res)?);
|
||||||
|
let ret = super::response(StatusCode::OK).body(body)?;
|
||||||
|
Ok(ret)
|
||||||
|
}
|
||||||
|
_ => Ok(response(StatusCode::NOT_ACCEPTABLE).body(Body::empty())?),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user