Skip to content

Commit

Permalink
fix other instances of error typing
Browse files Browse the repository at this point in the history
  • Loading branch information
samtfm committed Apr 26, 2021
1 parent ef52770 commit 1c4b37e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 9 additions & 7 deletions superset-frontend/src/views/CRUD/hooks.ts
Expand Up @@ -205,7 +205,7 @@ export function useListViewResource<D extends object = any>(
interface SingleViewResourceState<D extends object = any> {
loading: boolean;
resource: D | null;
error: string | Record<string, string[]> | null;
error: string | Record<string, string[] | string> | null;
}

export function useSingleViewResource<D extends object = any>(
Expand Down Expand Up @@ -241,7 +241,7 @@ export function useSingleViewResource<D extends object = any>(
});
return json.result;
},
createErrorHandler((errMsg: Record<string, string[]>) => {
createErrorHandler((errMsg: Record<string, string[] | string>) => {
handleErrorMsg(
t(
'An error occurred while fetching %ss: %s',
Expand Down Expand Up @@ -282,7 +282,7 @@ export function useSingleViewResource<D extends object = any>(
});
return json.id;
},
createErrorHandler((errMsg: Record<string, string[]>) => {
createErrorHandler((errMsg: Record<string, string[] | string>) => {
handleErrorMsg(
t(
'An error occurred while creating %ss: %s',
Expand Down Expand Up @@ -396,19 +396,21 @@ export function useImportResource(
payload.includes('already exists and `overwrite=true` was not passed');

const getPasswordsNeeded = (
errMsg: Record<string, Record<string, string[]>>,
errMsg: Record<string, Record<string, string[] | string>>,
) =>
Object.entries(errMsg)
.filter(([, validationErrors]) => isNeedsPassword(validationErrors))
.map(([fileName]) => fileName);

const getAlreadyExists = (errMsg: Record<string, Record<string, string[]>>) =>
const getAlreadyExists = (
errMsg: Record<string, Record<string, string[] | string>>,
) =>
Object.entries(errMsg)
.filter(([, validationErrors]) => isAlreadyExists(validationErrors))
.map(([fileName]) => fileName);

const hasTerminalValidation = (
errMsg: Record<string, Record<string, string[]>>,
errMsg: Record<string, Record<string, string[] | string>>,
) =>
Object.values(errMsg).some(
validationErrors =>
Expand Down Expand Up @@ -636,7 +638,7 @@ export const testDatabaseConnection = (
() => {
addSuccessToast(t('Connection looks good!'));
},
createErrorHandler((errMsg: Record<string, string[]> | string) => {
createErrorHandler((errMsg: Record<string, string[] | string> | string) => {
handleErrorMsg(t(`${t('ERROR: ')}${parsedErrorMessage(errMsg)}`));
}),
);
Expand Down
4 changes: 3 additions & 1 deletion superset-frontend/src/views/CRUD/utils.tsx
Expand Up @@ -155,7 +155,9 @@ export const createFetchRelated = createFetchResourceMethod('related');
export const createFetchDistinct = createFetchResourceMethod('distinct');

export function createErrorHandler(
handleErrorFunc: (errMsg?: string | Record<string, string[]>) => void,
handleErrorFunc: (
errMsg?: string | Record<string, string[] | string>,
) => void,
) {
return async (e: SupersetClientResponse | string) => {
const parsedError = await getClientErrorObject(e);
Expand Down

0 comments on commit 1c4b37e

Please sign in to comment.