33import { env } from "@/env.mjs" ;
44import { ErrorCode } from "@/lib/errorCodes" ;
55import { notAuthenticated , notFound , orgNotFound , secretAlreadyExists , ServiceError , ServiceErrorException , unexpectedError } from "@/lib/serviceError" ;
6- import { CodeHostType , isServiceError } from "@/lib/utils" ;
6+ import { CodeHostType , isHttpError , isServiceError } from "@/lib/utils" ;
77import { prisma } from "@/prisma" ;
88import { render } from "@react-email/components" ;
99import * as Sentry from '@sentry/nextjs' ;
@@ -851,14 +851,16 @@ export const experimental_addGithubRepositoryByUrl = async (repositoryUrl: strin
851851 repo,
852852 } ) ;
853853 githubRepo = response . data ;
854- } catch ( error : any ) {
855- if ( error . status === 404 ) {
854+ } catch ( error ) {
855+ if ( isHttpError ( error , 404 ) ) {
856856 return {
857857 statusCode : StatusCodes . NOT_FOUND ,
858858 errorCode : ErrorCode . INVALID_REQUEST_BODY ,
859859 message : `Repository '${ owner } /${ repo } ' not found or is private. Only public repositories can be added.` ,
860860 } satisfies ServiceError ;
861- } else if ( error . status === 403 ) {
861+ }
862+
863+ if ( isHttpError ( error , 403 ) ) {
862864 return {
863865 statusCode : StatusCodes . FORBIDDEN ,
864866 errorCode : ErrorCode . INVALID_REQUEST_BODY ,
@@ -869,7 +871,7 @@ export const experimental_addGithubRepositoryByUrl = async (repositoryUrl: strin
869871 return {
870872 statusCode : StatusCodes . INTERNAL_SERVER_ERROR ,
871873 errorCode : ErrorCode . INVALID_REQUEST_BODY ,
872- message : `Failed to fetch repository information: ${ error . message || 'Unknown error' } ` ,
874+ message : `Failed to fetch repository information: ${ error instanceof Error ? error . message : 'Unknown error' } ` ,
873875 } satisfies ServiceError ;
874876 }
875877
0 commit comments