From 0d55f9226639858e846f26cac3a5b9a892309382 Mon Sep 17 00:00:00 2001 From: Eric Duong Date: Tue, 6 Feb 2024 11:49:03 -0500 Subject: [PATCH] chore(data-warehouse): add error handling to postgres modal form (#20159) add error handling to postgres modal form --- .../data-warehouse/external/forms/sourceFormLogic.ts | 3 +++ posthog/warehouse/api/external_data_source.py | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/src/scenes/data-warehouse/external/forms/sourceFormLogic.ts b/frontend/src/scenes/data-warehouse/external/forms/sourceFormLogic.ts index b49520c71fa67..1bca52f3bffbf 100644 --- a/frontend/src/scenes/data-warehouse/external/forms/sourceFormLogic.ts +++ b/frontend/src/scenes/data-warehouse/external/forms/sourceFormLogic.ts @@ -84,6 +84,9 @@ export const sourceFormLogic = kea([ submitExternalDataSourceFailure: ({ error }) => { lemonToast.error(error?.message || 'Something went wrong') }, + submitDatabaseSchemaFormFailure: ({ error }) => { + lemonToast.error(error?.message || 'Something went wrong') + }, handleRedirect: async ({ kind, searchParams }) => { switch (kind) { case 'hubspot': { diff --git a/posthog/warehouse/api/external_data_source.py b/posthog/warehouse/api/external_data_source.py index 6078e9d8cd6da..faf884d6c8b3b 100644 --- a/posthog/warehouse/api/external_data_source.py +++ b/posthog/warehouse/api/external_data_source.py @@ -341,7 +341,15 @@ def database_schema(self, request: Request, *arg: Any, **kwargs: Any): data={"message": "Cannot use internal Postgres database"}, ) - result = get_postgres_schemas(host, port, database, user, password, schema) + try: + result = get_postgres_schemas(host, port, database, user, password, schema) + except Exception as e: + logger.exception("Could not fetch Postgres schemas", exc_info=e) + return Response( + status=status.HTTP_400_BAD_REQUEST, + data={"message": "Could not fetch Postgres schemas. Please check all connection details are valid."}, + ) + result_mapped_to_options = [{"table": row, "should_sync": False} for row in result] return Response(status=status.HTTP_200_OK, data=result_mapped_to_options)