@@ -7,6 +7,8 @@ import { PrismaClient } from "@sourcebot/db";
7
7
import { FALLBACK_GITHUB_TOKEN } from "./environment.js" ;
8
8
import { BackendException , BackendError } from "@sourcebot/error" ;
9
9
import { processPromiseResults , throwIfAnyFailed } from "./connectionUtils.js" ;
10
+ import * as Sentry from "@sentry/node" ;
11
+
10
12
const logger = createLogger ( "GitHub" ) ;
11
13
12
14
export type OctokitRepository = {
@@ -53,15 +55,21 @@ export const getGitHubReposFromConfig = async (config: GithubConnectionConfig, o
53
55
try {
54
56
await octokit . rest . users . getAuthenticated ( ) ;
55
57
} catch ( error ) {
58
+ Sentry . captureException ( error ) ;
59
+
56
60
if ( isHttpError ( error , 401 ) ) {
57
- throw new BackendException ( BackendError . CONNECTION_SYNC_INVALID_TOKEN , {
61
+ const e = new BackendException ( BackendError . CONNECTION_SYNC_INVALID_TOKEN , {
58
62
secretKey,
59
63
} ) ;
64
+ Sentry . captureException ( e ) ;
65
+ throw e ;
60
66
}
61
67
62
- throw new BackendException ( BackendError . CONNECTION_SYNC_SYSTEM_ERROR , {
68
+ const e = new BackendException ( BackendError . CONNECTION_SYNC_SYSTEM_ERROR , {
63
69
message : `Failed to authenticate with GitHub` ,
64
70
} ) ;
71
+ Sentry . captureException ( e ) ;
72
+ throw e ;
65
73
}
66
74
}
67
75
@@ -239,6 +247,8 @@ const getReposOwnedByUsers = async (users: string[], isAuthenticated: boolean, o
239
247
data
240
248
} ;
241
249
} catch ( error ) {
250
+ Sentry . captureException ( error ) ;
251
+
242
252
if ( isHttpError ( error , 404 ) ) {
243
253
logger . error ( `User ${ user } not found or no access` ) ;
244
254
return {
@@ -282,6 +292,8 @@ const getReposForOrgs = async (orgs: string[], octokit: Octokit, signal: AbortSi
282
292
data
283
293
} ;
284
294
} catch ( error ) {
295
+ Sentry . captureException ( error ) ;
296
+
285
297
if ( isHttpError ( error , 404 ) ) {
286
298
logger . error ( `Organization ${ org } not found or no access` ) ;
287
299
return {
@@ -327,6 +339,8 @@ const getRepos = async (repoList: string[], octokit: Octokit, signal: AbortSigna
327
339
} ;
328
340
329
341
} catch ( error ) {
342
+ Sentry . captureException ( error ) ;
343
+
330
344
if ( isHttpError ( error , 404 ) ) {
331
345
logger . error ( `Repository ${ repo } not found or no access` ) ;
332
346
return {
0 commit comments