From bc65cf450912910d0cc45915c00c775a386f6565 Mon Sep 17 00:00:00 2001 From: Phillip Kelley-Dotson Date: Tue, 8 Mar 2022 16:21:12 -0800 Subject: [PATCH] fix: ensure validation for db modal for googlesheets (#19018) * fix: ensure validation for db modal for googlesheets * chain async function (cherry picked from commit bb17decb0652bd2cfc64dda15e88bbccec2b8065) --- superset-frontend/src/views/CRUD/hooks.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/superset-frontend/src/views/CRUD/hooks.ts b/superset-frontend/src/views/CRUD/hooks.ts index ae4b041f66878..ae58aef0d9e0f 100644 --- a/superset-frontend/src/views/CRUD/hooks.ts +++ b/superset-frontend/src/views/CRUD/hooks.ts @@ -649,7 +649,7 @@ export function useDatabaseValidation() { null, ); const getValidation = useCallback( - (database: Partial | null, onCreate = false) => { + (database: Partial | null, onCreate = false) => SupersetClient.post({ endpoint: '/api/v1/database/validate_parameters', body: JSON.stringify(database), @@ -658,9 +658,10 @@ export function useDatabaseValidation() { .then(() => { setValidationErrors(null); }) + // eslint-disable-next-line consistent-return .catch(e => { if (typeof e.json === 'function') { - e.json().then(({ errors = [] }: JsonObject) => { + return e.json().then(({ errors = [] }: JsonObject) => { const parsedErrors = errors .filter((error: { error_type: string }) => { const skipValidationError = ![ @@ -748,12 +749,10 @@ export function useDatabaseValidation() { ); setValidationErrors(parsedErrors); }); - } else { - // eslint-disable-next-line no-console - console.error(e); } - }); - }, + // eslint-disable-next-line no-console + console.error(e); + }), [setValidationErrors], );