Skip to content

Commit

Permalink
fix(webserver): report all errors in integration status (#2352)
Browse files Browse the repository at this point in the history
  • Loading branch information
boxbeam authored and wsxiaoys committed Jun 6, 2024
1 parent cf81360 commit 31fae30
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 43 deletions.
8 changes: 2 additions & 6 deletions ee/tabby-webserver/src/service/repository/third_party.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,16 @@ impl ThirdPartyRepositoryService for ThirdPartyRepositoryServiceImpl {
.await
{
Ok(repos) => repos,
Err((e, true)) => {
Err(e) => {
self.integration
.update_integration_sync_status(provider.id.clone(), Some(e.to_string()))
.await?;
error!(
"Credentials for integration {} are expired or invalid",
"Failed to fetch repositories from integration: {}",
provider.display_name
);
return Err(e.into());
}
Err((e, false)) => {
error!("Failed to fetch repositories from github: {e}");
return Err(e.into());
}
};

refresh_repositories_for_provider(self, &*self.integration, provider, repos).await?;
Expand Down
20 changes: 3 additions & 17 deletions ee/tabby-webserver/src/service/repository/third_party/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use octocrab::GitHubError;
use tabby_schema::integration::IntegrationKind;

use self::{github::fetch_all_github_repos, gitlab::fetch_all_gitlab_repos};
Expand All @@ -16,26 +15,13 @@ pub async fn fetch_all_repos(
kind: IntegrationKind,
access_token: &str,
api_base: &str,
) -> Result<Vec<RepositoryInfo>, (anyhow::Error, bool)> {
) -> Result<Vec<RepositoryInfo>, anyhow::Error> {
match kind {
IntegrationKind::Github | IntegrationKind::GithubSelfHosted => {
match fetch_all_github_repos(access_token, api_base).await {
Ok(repos) => Ok(repos),
Err(octocrab::Error::GitHub {
source: source @ GitHubError { .. },
..
}) if source.status_code.is_client_error() => Err((source.into(), true)),
Err(e) => Err((e.into(), false)),
}
Ok(fetch_all_github_repos(access_token, api_base).await?)
}
IntegrationKind::Gitlab | IntegrationKind::GitlabSelfHosted => {
match fetch_all_gitlab_repos(access_token, api_base).await {
Ok(repos) => Ok(repos),
Err(e) => {
let client_error = e.is_client_error();
Err((e.into(), client_error))
}
}
Ok(fetch_all_gitlab_repos(access_token, api_base).await?)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use gitlab::{
api::{projects::Projects, ApiError, AsyncQuery, Pagination},
api::{projects::Projects, AsyncQuery, Pagination},
GitlabBuilder,
};
use serde::Deserialize;
Expand All @@ -23,25 +23,6 @@ pub enum GitlabError {
Projects(#[from] gitlab::api::projects::ProjectsBuilderError),
}

impl GitlabError {
pub fn is_client_error(&self) -> bool {
match self {
GitlabError::Rest(source)
| GitlabError::Gitlab(gitlab::GitlabError::Api { source }) => {
matches!(
source,
ApiError::Auth { .. }
| ApiError::Client {
source: gitlab::RestError::AuthError { .. }
}
| ApiError::Gitlab { .. }
)
}
_ => false,
}
}
}

pub async fn fetch_all_gitlab_repos(
access_token: &str,
api_base: &str,
Expand Down

0 comments on commit 31fae30

Please sign in to comment.