diff --git a/app/client/src/sagas/DatasourcesSagas.ts b/app/client/src/sagas/DatasourcesSagas.ts index b05c609664ed..8d9b77bf4e32 100644 --- a/app/client/src/sagas/DatasourcesSagas.ts +++ b/app/client/src/sagas/DatasourcesSagas.ts @@ -929,7 +929,7 @@ function* testDatasourceSaga(actionPayload: ReduxAction) { id: datasource.id, environmentId: currentEnvironment, show: true, - error: { message: responseData.invalids.join(", ") }, + error: { message: responseData.invalids.join("\n") }, }, }); AppsmithConsole.error({ diff --git a/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java b/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java index 8a6db99d5a6d..a27e2ecc8e9b 100644 --- a/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java +++ b/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java @@ -47,6 +47,8 @@ import org.pf4j.Extension; import org.pf4j.PluginWrapper; import org.postgresql.util.PGobject; +import org.postgresql.util.PSQLException; +import org.postgresql.util.PSQLState; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import reactor.core.publisher.Mono; @@ -1347,10 +1349,21 @@ private static HikariDataSource createConnectionPool( try { datasource = new HikariDataSource(config); } catch (PoolInitializationException e) { + Throwable cause = e.getCause(); + if (cause instanceof PSQLException) { + PSQLException psqlException = (PSQLException) cause; + String sqlState = psqlException.getSQLState(); + if (PSQLState.CONNECTION_UNABLE_TO_CONNECT.getState().equals(sqlState)) { + throw new AppsmithPluginException( + AppsmithPluginError.PLUGIN_DATASOURCE_ARGUMENT_ERROR, + PostgresErrorMessages.DS_INVALID_HOSTNAME_AND_PORT_MSG, + psqlException.getMessage()); + } + } throw new AppsmithPluginException( AppsmithPluginError.PLUGIN_DATASOURCE_ARGUMENT_ERROR, PostgresErrorMessages.CONNECTION_POOL_CREATION_FAILED_ERROR_MSG, - e.getMessage()); + cause != null ? cause.getMessage() : e.getMessage()); } return datasource; diff --git a/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/exceptions/PostgresErrorMessages.java b/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/exceptions/PostgresErrorMessages.java index daee36541178..8cee7970b58a 100644 --- a/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/exceptions/PostgresErrorMessages.java +++ b/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/exceptions/PostgresErrorMessages.java @@ -49,4 +49,6 @@ public class PostgresErrorMessages extends BasePluginErrorMessages { public static final String DS_MISSING_PASSWORD_ERROR_MSG = "Missing password for authentication."; public static final String DS_MISSING_DATABASE_NAME_ERROR_MSG = "Missing database name."; + + public static final String DS_INVALID_HOSTNAME_AND_PORT_MSG = "Please check the host and port."; }