notion_client/endpoints/blocks/
delete.rs1use crate::{
2 endpoints::NOTION_URI,
3 objects::{block::Block, Response},
4 NotionClientError,
5};
6
7use super::BlocksEndpoint;
8
9impl BlocksEndpoint {
10 pub async fn delete_a_block(&self, block_id: &str) -> Result<Block, NotionClientError> {
11 let result = self
12 .client
13 .delete(format!(
14 "{notion_uri}/blocks/{block_id}",
15 notion_uri = NOTION_URI,
16 block_id = block_id
17 ))
18 .send()
19 .await
20 .map_err(|e| NotionClientError::FailedToRequest { source: e })?;
21
22 let body = result
23 .text()
24 .await
25 .map_err(|e| NotionClientError::FailedToText { source: e })?;
26
27 let response = serde_json::from_str(&body)
28 .map_err(|e| NotionClientError::FailedToDeserialize { source: e, body })?;
29
30 match response {
31 Response::Success(r) => Ok(r),
32 Response::Error(e) => Err(NotionClientError::InvalidStatusCode { error: e }),
33 }
34 }
35}