commit
49bca9cde8
@ -213,7 +213,7 @@ pub enum ParseRequestError {
|
|||||||
|
|
||||||
/// The request's syntax was invalid.
|
/// The request's syntax was invalid.
|
||||||
#[error("Invalid request: {0}")]
|
#[error("Invalid request: {0}")]
|
||||||
InvalidRequest(serde_json::Error),
|
InvalidRequest(Box<dyn std::error::Error>),
|
||||||
|
|
||||||
/// The request's files map was invalid.
|
/// The request's files map was invalid.
|
||||||
#[error("Invalid files map: {0}")]
|
#[error("Invalid files map: {0}")]
|
||||||
|
@ -52,15 +52,17 @@ pub async fn receive_batch_json(body: impl AsyncRead) -> Result<BatchRequest, Pa
|
|||||||
body.read_to_end(&mut data)
|
body.read_to_end(&mut data)
|
||||||
.await
|
.await
|
||||||
.map_err(ParseRequestError::Io)?;
|
.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> {
|
pub async fn receive_batch_cbor(body: impl AsyncRead) -> Result<BatchRequest, ParseRequestError> {
|
||||||
let mut data = Vec::new();
|
let mut data = Vec::new();
|
||||||
futures_util::pin_mut!(body);
|
futures_util::pin_mut!(body);
|
||||||
body.read_to_end(&mut data)
|
body.read_to_end(&mut data)
|
||||||
.await
|
.await
|
||||||
.map_err(ParseRequestError::Io)?;
|
.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)))?)
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ pub(super) async fn receive_batch_multipart(
|
|||||||
let request_str = field.text().await?;
|
let request_str = field.text().await?;
|
||||||
request = Some(
|
request = Some(
|
||||||
serde_json::from_str::<BatchRequest>(&request_str)
|
serde_json::from_str::<BatchRequest>(&request_str)
|
||||||
.map_err(ParseRequestError::InvalidRequest)?,
|
.map_err(|e| ParseRequestError::InvalidRequest(Box::new(e)))?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Some("map") => {
|
Some("map") => {
|
||||||
|
Loading…
Reference in New Issue
Block a user