mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 16:27:46 +00:00
fix: propogate Github app connection errors to the client properly (#4177)
* fix: propogate github errors to the client properly
This commit is contained in:
@@ -145,12 +145,20 @@ export const getGitHubEnvironments = async (appConnection: TGitHubConnection, ow
|
|||||||
};
|
};
|
||||||
|
|
||||||
type TokenRespData = {
|
type TokenRespData = {
|
||||||
access_token: string;
|
access_token?: string;
|
||||||
scope: string;
|
scope: string;
|
||||||
token_type: string;
|
token_type: string;
|
||||||
error?: string;
|
error?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function isErrorResponse(data: TokenRespData): data is TokenRespData & {
|
||||||
|
error: string;
|
||||||
|
error_description: string;
|
||||||
|
error_uri: string;
|
||||||
|
} {
|
||||||
|
return "error" in data;
|
||||||
|
}
|
||||||
|
|
||||||
export const validateGitHubConnectionCredentials = async (config: TGitHubConnectionConfig) => {
|
export const validateGitHubConnectionCredentials = async (config: TGitHubConnectionConfig) => {
|
||||||
const { credentials, method } = config;
|
const { credentials, method } = config;
|
||||||
|
|
||||||
@@ -198,7 +206,17 @@ export const validateGitHubConnectionCredentials = async (config: TGitHubConnect
|
|||||||
"Accept-Encoding": "application/json"
|
"Accept-Encoding": "application/json"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (isErrorResponse(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) {
|
} catch (e: unknown) {
|
||||||
|
if (e instanceof BadRequestError) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
throw new BadRequestError({
|
throw new BadRequestError({
|
||||||
message: `Unable to validate connection: verify credentials`
|
message: `Unable to validate connection: verify credentials`
|
||||||
});
|
});
|
||||||
@@ -211,6 +229,10 @@ export const validateGitHubConnectionCredentials = async (config: TGitHubConnect
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (method === GitHubConnectionMethod.App) {
|
if (method === GitHubConnectionMethod.App) {
|
||||||
|
if (!tokenResp.data.access_token) {
|
||||||
|
throw new InternalServerError({ message: `Missing access token: ${tokenResp.data.error}` });
|
||||||
|
}
|
||||||
|
|
||||||
const installationsResp = await request.get<{
|
const installationsResp = await request.get<{
|
||||||
installations: {
|
installations: {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -239,10 +261,6 @@ export const validateGitHubConnectionCredentials = async (config: TGitHubConnect
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tokenResp.data.access_token) {
|
|
||||||
throw new InternalServerError({ message: `Missing access token: ${tokenResp.data.error}` });
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case GitHubConnectionMethod.App:
|
case GitHubConnectionMethod.App:
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user