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