misc: boxed error

This commit is contained in:
Miaxos 2021-07-26 17:32:49 +00:00
parent 37e6a1b715
commit 02df4f1c24
3 changed files with 7 additions and 5 deletions

View File

@ -213,7 +213,7 @@ pub enum ParseRequestError {
/// The request's syntax was invalid.
#[error("Invalid request: {0}")]
InvalidRequest(serde_json::Error),
InvalidRequest(Box<dyn std::error::Error>),
/// The request's files map was invalid.
#[error("Invalid files map: {0}")]

View File

@ -52,15 +52,17 @@ pub async fn receive_batch_json(body: impl AsyncRead) -> Result<BatchRequest, Pa
body.read_to_end(&mut data)
.await
.map_err(ParseRequestError::Io)?;
Ok(serde_json::from_slice::<BatchRequest>(&data).map_err(ParseRequestError::InvalidRequest)?)
Ok(serde_json::from_slice::<BatchRequest>(&data)
.map_err(|e| ParseRequestError::InvalidRequest(Box::new(e)))?)
}
/// Receive a GraphQL request from a body as CBOR
pub async fn receive_batch_cbor(body: impl AsyncRead) -> Result<BatchRequest, ParseRequestError> {
let mut data = Vec::new();
futures_util::pin_mut!(body);
body.read_to_end(&mut data)
.await
.map_err(ParseRequestError::Io)?;
Ok(serde_cbor::from_slice::<BatchRequest>(&data).map_err(ParseRequestError::InvalidRequest)?)
Ok(serde_cbor::from_slice::<BatchRequest>(&data)
.map_err(|e| ParseRequestError::InvalidRequest(Box::new(e)))?)
}

View File

@ -70,7 +70,7 @@ pub(super) async fn receive_batch_multipart(
let request_str = field.text().await?;
request = Some(
serde_json::from_str::<BatchRequest>(&request_str)
.map_err(ParseRequestError::InvalidRequest)?,
.map_err(|e| ParseRequestError::InvalidRequest(Box::new(e)))?,
);
}
Some("map") => {