fix: ensure validation for db modal for googlesheets (#19018)

* fix: ensure validation for db modal for googlesheets

* chain async function
This commit is contained in:
Phillip Kelley-Dotson 2022-03-08 16:21:12 -08:00 committed by GitHub
parent 7af26a0492
commit bb17decb06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 7 deletions

View File

@ -649,7 +649,7 @@ export function useDatabaseValidation() {
null,
);
const getValidation = useCallback(
(database: Partial<DatabaseObject> | null, onCreate = false) => {
(database: Partial<DatabaseObject> | 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],
);