fix: replaced unwraps with expects

This commit is contained in:
Bram Dingelstad 2024-03-22 21:24:07 +01:00
parent 83cc5e85fc
commit f0b58940b2

View file

@ -75,11 +75,11 @@ impl From<chrono::ParseError> for Error {
fn get_http_client(notion_api_key: &str) -> surf::Client {
surf::Config::new()
.add_header("Authorization", format!("Bearer {notion_api_key}"))
.unwrap()
.expect("to add Authorization header")
.add_header("Notion-Version", NOTION_VERSION)
.unwrap()
.expect("to add Notion-Version header")
.add_header("Content-Type", "application/json")
.unwrap()
.expect("to add Content-Type header")
.try_into()
.expect("to build a valid client out of notion_api_key")
}
@ -190,9 +190,11 @@ impl<'a> Client {
.http_client
.post("https://api.notion.com/v1/search")
.body_json(&options)
.unwrap();
.expect("to parse JSON for doing `search`");
let mut response = (self.request_handler)(&mut request).await.unwrap();
let mut response = (self.request_handler)(&mut request)
.await
.expect("to request through a request handler");
Ok(response.body_json().await?)
// TODO: re-implement wrong return from Notion
@ -341,7 +343,9 @@ impl Databases {
};
if let Some(json) = json {
request = request.body_json(&json).unwrap();
request = request
.body_json(&json)
.expect("to parse JSON for start_cursor");
}
let mut response = (self.request_handler)(&mut request).await?;
@ -948,7 +952,7 @@ where
serde_json::from_value::<DatabaseProperty>(value.to_owned()).unwrap_or_else(|error| {
log::warn!(
"Could not parse value because of error, defaulting to DatabaseProperty::Unsupported:\n= ERROR:\n{error:#?}\n= JSON:\n{:#?}\n---",
serde_json::to_string_pretty(&value).unwrap()
serde_json::to_string_pretty(&value).expect("to pretty print the database property error")
);
DatabaseProperty::Unsupported(value.to_owned())
}),
@ -1214,7 +1218,7 @@ where
serde_json::from_value::<Property>(value.to_owned()).unwrap_or_else(|error| {
log::warn!(
"Could not parse value because of error, defaulting to Property::Unsupported:\n= ERROR:\n{error:#?}\n= JSON:\n{}\n---",
serde_json::to_string_pretty(&value).unwrap()
serde_json::to_string_pretty(&value).expect("to pretty print Property errors")
);
Property::Unsupported(value.to_owned())
}),