Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

improvement: move client instantation to try/catch for sql connection validation for error propogation

Scott Wilsona4eb2e77c2b6
diff --git a/backend/src/services/app-connection/shared/sql/sql-connection-fns.ts b/backend/src/services/app-connection/shared/sql/sql-connection-fns.ts
index ed1d999416..bc98e9bcce 100644
--- a/backend/src/services/app-connection/shared/sql/sql-connection-fns.ts
+++ b/backend/src/services/app-connection/shared/sql/sql-connection-fns.ts
@@ -77,20 +77,22 @@ export const getSqlConnectionClient = async (appConnection: Pick<TSqlConnection,
export const validateSqlConnectionCredentials = async (config: TSqlConnectionConfig) => {
const { credentials, app } = config;
- const client = await getSqlConnectionClient({ app, credentials });
+ let client: Knex | undefined;
try {
+ client = await getSqlConnectionClient({ app, credentials });
+
await client.raw(`Select 1`);
return credentials;
} catch (error) {
throw new BadRequestError({
- message:
- (error as Error)?.message?.replaceAll(credentials.password, "********************") ??
- "Unable to validate connection: verify credentials"
+ message: `Unable to validate connection: ${
+ (error as Error)?.message?.replaceAll(credentials.password, "********************") ?? "verify credentials"
+ }`
});
} finally {
- await client.destroy();
+ await client?.destroy();
}
};