diff --git a/packages/server/src/integrations/index.ts b/packages/server/src/integrations/index.ts index 82432dfa2c..5a2271de25 100644 --- a/packages/server/src/integrations/index.ts +++ b/packages/server/src/integrations/index.ts @@ -122,7 +122,7 @@ export async function getIntegration(integration: SourceName) { } const VALIDATORS: Partial< - Record Promise> + Record Promise> > = { [SourceName.POSTGRES]: postgres.validateConnection, } diff --git a/packages/server/src/integrations/postgres.ts b/packages/server/src/integrations/postgres.ts index d84ea273c4..c452b8afc7 100644 --- a/packages/server/src/integrations/postgres.ts +++ b/packages/server/src/integrations/postgres.ts @@ -335,8 +335,8 @@ async function validateConnection(config: PostgresConfig) { try { await integration.openConnection() return true - } catch { - return false + } catch (e: any) { + return { error: e.message as string } } finally { await integration.closeConnection() } diff --git a/packages/server/src/sdk/tests/datasources/validators.spec.ts b/packages/server/src/sdk/tests/datasources/validators.spec.ts index 700953feea..677ff8b59c 100644 --- a/packages/server/src/sdk/tests/datasources/validators.spec.ts +++ b/packages/server/src/sdk/tests/datasources/validators.spec.ts @@ -37,22 +37,20 @@ describe("datasource validators", () => { }) it("test invalid connection string", async () => { - try { - const result = await validator({ - host, - port, - database: "postgres", - user: "wrong", - password: "password", - schema: "public", - ssl: false, - rejectUnauthorized: false, - ca: false, - }) - expect(result).toBeFalsy() - } catch (e) { - console.error(e) - } + const result = await validator({ + host, + port, + database: "postgres", + user: "wrong", + password: "password", + schema: "public", + ssl: false, + rejectUnauthorized: false, + ca: false, + }) + expect(result).toEqual({ + error: 'password authentication failed for user "wrong"', + }) }) }) })