diff options
author | Cyborus <cyborus@cyborus.xyz> | 2023-12-11 06:36:13 +0100 |
---|---|---|
committer | Cyborus <cyborus@cyborus.xyz> | 2023-12-11 21:50:39 +0100 |
commit | 5da7e69f82fe198a5f3f1284975b306344529eac (patch) | |
tree | 80af695e50036e05940312e416f9d236c58698bf /src/lib.rs | |
parent | merging a pr does not return a body (diff) | |
download | forgejo-api-5da7e69f82fe198a5f3f1284975b306344529eac.tar.xz forgejo-api-5da7e69f82fe198a5f3f1284975b306344529eac.zip |
checking if a pr exists does not return a body
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -88,6 +88,12 @@ impl Forgejo { self.execute_str(request).await } + async fn get_exists(&self, path: &str) -> Result<bool, ForgejoError> { + let url = self.url.join("api/v1/").unwrap().join(path).unwrap(); + let request = self.client.get(url).build()?; + self.execute_exists(request).await + } + async fn post<T: Serialize, U: DeserializeOwned>( &self, path: &str, @@ -222,6 +228,23 @@ impl Forgejo { status => Err(ForgejoError::UnexpectedStatusCode(status)), } } + + /// Like `execute`, but returns `false` on 404. + async fn execute_exists( + &self, + request: Request, + ) -> Result<bool, ForgejoError> { + let response = self.client.execute(request).await?; + match response.status() { + status if status.is_success() => Ok(true), + StatusCode::NOT_FOUND => Ok(false), + status if status.is_client_error() => Err(ForgejoError::ApiError( + status, + response.json::<ErrorMessage>().await?.message.unwrap_or_else(|| String::from("[no message]")), + )), + status => Err(ForgejoError::UnexpectedStatusCode(status)), + } + } } #[derive(serde::Deserialize)] |