From d87934cd757761bbd7df01da8251b2b572fab523 Mon Sep 17 00:00:00 2001 From: Phillip Kelley-Dotson Date: Fri, 4 Mar 2022 08:21:08 -0800 Subject: [PATCH] chain async function --- superset-frontend/src/views/CRUD/hooks.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/superset-frontend/src/views/CRUD/hooks.ts b/superset-frontend/src/views/CRUD/hooks.ts index ad9f9785d36d..ae58aef0d9e0 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,10 +658,10 @@ export function useDatabaseValidation() { .then(() => { setValidationErrors(null); }) + // eslint-disable-next-line consistent-return .catch(e => { - setValidationErrors(null); 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 = ![ @@ -749,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], );