mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-21 03:42:16 +00:00
fix: Show a more user friendly error message if initial Db connection times out (#10682)
This commit is contained in:
@@ -132,3 +132,9 @@ export function getConnectionOptions(): DataSourceOptions {
|
||||
throw new ApplicationError('Database type currently not supported', { extra: { dbType } });
|
||||
}
|
||||
}
|
||||
|
||||
export function arePostgresOptions(
|
||||
options: DataSourceOptions,
|
||||
): options is PostgresConnectionOptions {
|
||||
return options.type === 'postgres';
|
||||
}
|
||||
|
||||
@@ -3,12 +3,16 @@ import { Container } from 'typedi';
|
||||
import type { EntityManager } from '@n8n/typeorm';
|
||||
// eslint-disable-next-line n8n-local-rules/misplaced-n8n-typeorm-import
|
||||
import { DataSource as Connection } from '@n8n/typeorm';
|
||||
import { ErrorReporterProxy as ErrorReporter } from 'n8n-workflow';
|
||||
import {
|
||||
DbConnectionTimeoutError,
|
||||
ensureError,
|
||||
ErrorReporterProxy as ErrorReporter,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { inTest } from '@/constants';
|
||||
import { wrapMigration } from '@/databases/utils/migration-helpers';
|
||||
import type { Migration } from '@/databases/types';
|
||||
import { getConnectionOptions } from '@/databases/config';
|
||||
import { getConnectionOptions, arePostgresOptions } from '@/databases/config';
|
||||
|
||||
let connection: Connection;
|
||||
|
||||
@@ -54,7 +58,22 @@ export async function init(): Promise<void> {
|
||||
const connectionOptions = getConnectionOptions();
|
||||
connection = new Connection(connectionOptions);
|
||||
Container.set(Connection, connection);
|
||||
await connection.initialize();
|
||||
try {
|
||||
await connection.initialize();
|
||||
} catch (e) {
|
||||
let error = ensureError(e);
|
||||
if (
|
||||
arePostgresOptions(connectionOptions) &&
|
||||
error.message === 'Connection terminated due to connection timeout'
|
||||
) {
|
||||
error = new DbConnectionTimeoutError({
|
||||
cause: error,
|
||||
configuredTimeoutInMs: connectionOptions.connectTimeoutMS!,
|
||||
});
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
connectionState.connected = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user