mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 15:27:46 +00:00
improvement: move client instantation to try/catch for sql connection validation for error propogation
This commit is contained in:
@@ -77,20 +77,22 @@ export const getSqlConnectionClient = async (appConnection: Pick<TSqlConnection,
|
|||||||
export const validateSqlConnectionCredentials = async (config: TSqlConnectionConfig) => {
|
export const validateSqlConnectionCredentials = async (config: TSqlConnectionConfig) => {
|
||||||
const { credentials, app } = config;
|
const { credentials, app } = config;
|
||||||
|
|
||||||
const client = await getSqlConnectionClient({ app, credentials });
|
let client: Knex | undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
client = await getSqlConnectionClient({ app, credentials });
|
||||||
|
|
||||||
await client.raw(`Select 1`);
|
await client.raw(`Select 1`);
|
||||||
|
|
||||||
return credentials;
|
return credentials;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new BadRequestError({
|
throw new BadRequestError({
|
||||||
message:
|
message: `Unable to validate connection: ${
|
||||||
(error as Error)?.message?.replaceAll(credentials.password, "********************") ??
|
(error as Error)?.message?.replaceAll(credentials.password, "********************") ?? "verify credentials"
|
||||||
"Unable to validate connection: verify credentials"
|
}`
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
await client.destroy();
|
await client?.destroy();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user