Skip to content

Commit 4318c1d

Browse files
fix(backend): abort GitLab sync on non-404 API errors to prevent repo deletion
Previously, any HTTP error from the GitLab API (including 500s) was converted to a warning and the sync continued with a partial repo list. This caused the database reconciliation to delete repos from the failed group/user/project. Now only 404 errors are treated as warnings (resource not found or no access); all other errors abort the sync so the database is left untouched. Fixes #1029 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent bdab4b7 commit 4318c1d

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

packages/backend/src/gitlab.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,15 @@ export const getGitLabReposFromConfig = async (config: GitlabConnectionConfig) =
9696
Sentry.captureException(e);
9797
logger.error(`Failed to fetch projects for group ${group}.`, e);
9898

99-
const status = e?.cause?.response?.status;
100-
if (status !== undefined) {
101-
const warning = `GitLab API returned ${status}`
99+
if (e?.cause?.response?.status === 404) {
100+
const warning = `Group ${group} not found or no access`;
102101
logger.warn(warning);
103102
return {
104103
type: 'warning' as const,
105104
warning
106-
}
105+
};
107106
}
108107

109-
logger.error("No API response status returned");
110108
throw e;
111109
}
112110
}));
@@ -136,17 +134,15 @@ export const getGitLabReposFromConfig = async (config: GitlabConnectionConfig) =
136134
Sentry.captureException(e);
137135
logger.error(`Failed to fetch projects for user ${user}.`, e);
138136

139-
const status = e?.cause?.response?.status;
140-
if (status !== undefined) {
141-
const warning = `GitLab API returned ${status}`
137+
if (e?.cause?.response?.status === 404) {
138+
const warning = `User ${user} not found or no access`;
142139
logger.warn(warning);
143140
return {
144141
type: 'warning' as const,
145142
warning
146-
}
143+
};
147144
}
148145

149-
logger.error("No API response status returned");
150146
throw e;
151147
}
152148
}));
@@ -174,17 +170,15 @@ export const getGitLabReposFromConfig = async (config: GitlabConnectionConfig) =
174170
Sentry.captureException(e);
175171
logger.error(`Failed to fetch project ${project}.`, e);
176172

177-
const status = e?.cause?.response?.status;
178-
if (status !== undefined) {
179-
const warning = `GitLab API returned ${status}`
173+
if (e?.cause?.response?.status === 404) {
174+
const warning = `Project ${project} not found or no access`;
180175
logger.warn(warning);
181176
return {
182177
type: 'warning' as const,
183178
warning
184-
}
179+
};
185180
}
186181

187-
logger.error("No API response status returned");
188182
throw e;
189183
}
190184
}));

0 commit comments

Comments
 (0)