Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix: propogate github radar connection errors properly
sidwebworksd0e7af721e29
diff --git a/backend/src/services/app-connection/github-radar/github-radar-connection-fns.ts b/backend/src/services/app-connection/github-radar/github-radar-connection-fns.tsindex 84d7a1ce1d..fba852a0a0 100644--- a/backend/src/services/app-connection/github-radar/github-radar-connection-fns.ts+++ b/backend/src/services/app-connection/github-radar/github-radar-connection-fns.ts@@ -9,6 +9,7 @@ import { getAppConnectionMethodName } from "@app/services/app-connection/app-conimport { IntegrationUrls } from "@app/services/integration-auth/integration-list";import { AppConnection } from "../app-connection-enums";+import { GithubTokenRespData, isGithubErrorResponse } from "../github/github-connection-fns";import { GitHubRadarConnectionMethod } from "./github-radar-connection-enums";import {TGitHubRadarConnection,@@ -71,13 +72,6 @@ export const listGitHubRadarRepositories = async (appConnection: TGitHubRadarConreturn repositories;};-type TokenRespData = {- access_token: string;- scope: string;- token_type: string;- error?: string;-};-export const validateGitHubRadarConnectionCredentials = async (config: TGitHubRadarConnectionConfig) => {const { credentials, method } = config;@@ -93,10 +87,10 @@ export const validateGitHubRadarConnectionCredentials = async (config: TGitHubRa});}- let tokenResp: AxiosResponse<TokenRespData>;+ let tokenResp: AxiosResponse<GithubTokenRespData>;try {- tokenResp = await request.get<TokenRespData>("https://github.com/login/oauth/access_token", {+ tokenResp = await request.get<GithubTokenRespData>("https://github.com/login/oauth/access_token", {params: {client_id: INF_APP_CONNECTION_GITHUB_RADAR_APP_CLIENT_ID,client_secret: INF_APP_CONNECTION_GITHUB_RADAR_APP_CLIENT_SECRET,@@ -108,19 +102,27 @@ export const validateGitHubRadarConnectionCredentials = async (config: TGitHubRa"Accept-Encoding": "application/json"}});++ if (isGithubErrorResponse(tokenResp?.data)) {+ throw new BadRequestError({+ message: `Unable to validate credentials: GitHub responded with an error: ${tokenResp.data.error} - ${tokenResp.data.error_description}`+ });+ }} catch (e: unknown) {- throw new BadRequestError({- message: `Unable to validate connection: verify credentials`- });- }+ if (e instanceof BadRequestError) {+ throw e;+ }- if (tokenResp.status !== 200) {throw new BadRequestError({- message: `Unable to validate credentials: GitHub responded with a status code of ${tokenResp.status} (${tokenResp.statusText}). Verify credentials and try again.`+ message: `Unable to validate connection: verify credentials`});}if (method === GitHubRadarConnectionMethod.App) {+ if (!tokenResp.data.access_token) {+ throw new InternalServerError({ message: `Missing access token: ${tokenResp.data.error}` });+ }+const installationsResp = await request.get<{installations: {id: number;@@ -149,10 +151,6 @@ export const validateGitHubRadarConnectionCredentials = async (config: TGitHubRa}}- if (!tokenResp.data.access_token) {- throw new InternalServerError({ message: `Missing access token: ${tokenResp.data.error}` });- }-switch (method) {case GitHubRadarConnectionMethod.App:return {diff --git a/backend/src/services/app-connection/github/github-connection-fns.ts b/backend/src/services/app-connection/github/github-connection-fns.tsindex e4281625b7..360923e190 100644--- a/backend/src/services/app-connection/github/github-connection-fns.ts+++ b/backend/src/services/app-connection/github/github-connection-fns.ts@@ -144,14 +144,14 @@ export const getGitHubEnvironments = async (appConnection: TGitHubConnection, ow}};-type TokenRespData = {+export type GithubTokenRespData = {access_token?: string;scope: string;token_type: string;error?: string;};-function isErrorResponse(data: TokenRespData): data is TokenRespData & {+export function isGithubErrorResponse(data: GithubTokenRespData): data is GithubTokenRespData & {error: string;error_description: string;error_uri: string;@@ -191,10 +191,10 @@ export const validateGitHubConnectionCredentials = async (config: TGitHubConnect});}- let tokenResp: AxiosResponse<TokenRespData>;+ let tokenResp: AxiosResponse<GithubTokenRespData>;try {- tokenResp = await request.get<TokenRespData>("https://github.com/login/oauth/access_token", {+ tokenResp = await request.get<GithubTokenRespData>("https://github.com/login/oauth/access_token", {params: {client_id: clientId,client_secret: clientSecret,@@ -207,7 +207,7 @@ export const validateGitHubConnectionCredentials = async (config: TGitHubConnect}});- if (isErrorResponse(tokenResp?.data)) {+ if (isGithubErrorResponse(tokenResp?.data)) {throw new BadRequestError({message: `Unable to validate credentials: GitHub responded with an error: ${tokenResp.data.error} - ${tokenResp.data.error_description}`});