@@ -7,6 +7,8 @@ import { PrismaClient } from "@sourcebot/db";
77import { FALLBACK_GITHUB_TOKEN } from "./environment.js" ;
88import { BackendException , BackendError } from "@sourcebot/error" ;
99import { processPromiseResults , throwIfAnyFailed } from "./connectionUtils.js" ;
10+ import * as Sentry from "@sentry/node" ;
11+
1012const logger = createLogger ( "GitHub" ) ;
1113
1214export type OctokitRepository = {
@@ -53,15 +55,21 @@ export const getGitHubReposFromConfig = async (config: GithubConnectionConfig, o
5355 try {
5456 await octokit . rest . users . getAuthenticated ( ) ;
5557 } catch ( error ) {
58+ Sentry . captureException ( error ) ;
59+
5660 if ( isHttpError ( error , 401 ) ) {
57- throw new BackendException ( BackendError . CONNECTION_SYNC_INVALID_TOKEN , {
61+ const e = new BackendException ( BackendError . CONNECTION_SYNC_INVALID_TOKEN , {
5862 secretKey,
5963 } ) ;
64+ Sentry . captureException ( e ) ;
65+ throw e ;
6066 }
6167
62- throw new BackendException ( BackendError . CONNECTION_SYNC_SYSTEM_ERROR , {
68+ const e = new BackendException ( BackendError . CONNECTION_SYNC_SYSTEM_ERROR , {
6369 message : `Failed to authenticate with GitHub` ,
6470 } ) ;
71+ Sentry . captureException ( e ) ;
72+ throw e ;
6573 }
6674 }
6775
@@ -239,6 +247,8 @@ const getReposOwnedByUsers = async (users: string[], isAuthenticated: boolean, o
239247 data
240248 } ;
241249 } catch ( error ) {
250+ Sentry . captureException ( error ) ;
251+
242252 if ( isHttpError ( error , 404 ) ) {
243253 logger . error ( `User ${ user } not found or no access` ) ;
244254 return {
@@ -282,6 +292,8 @@ const getReposForOrgs = async (orgs: string[], octokit: Octokit, signal: AbortSi
282292 data
283293 } ;
284294 } catch ( error ) {
295+ Sentry . captureException ( error ) ;
296+
285297 if ( isHttpError ( error , 404 ) ) {
286298 logger . error ( `Organization ${ org } not found or no access` ) ;
287299 return {
@@ -327,6 +339,8 @@ const getRepos = async (repoList: string[], octokit: Octokit, signal: AbortSigna
327339 } ;
328340
329341 } catch ( error ) {
342+ Sentry . captureException ( error ) ;
343+
330344 if ( isHttpError ( error , 404 ) ) {
331345 logger . error ( `Repository ${ repo } not found or no access` ) ;
332346 return {
0 commit comments