mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-23 08:28:10 +00:00
[issue 5222] remove redundant code used to check API response (#5223)
* [issue 5222] remove redundant code used to check API response * minor fix
This commit is contained in:
parent
96486d745e
commit
1df1df616f
@ -15,7 +15,7 @@ import { AxiosResponse } from 'axios';
|
|||||||
import { isNil } from 'lodash';
|
import { isNil } from 'lodash';
|
||||||
import { Dashboard } from '../generated/entity/data/dashboard';
|
import { Dashboard } from '../generated/entity/data/dashboard';
|
||||||
import { getURLWithQueryFields } from '../utils/APIUtils';
|
import { getURLWithQueryFields } from '../utils/APIUtils';
|
||||||
import APIClient from './index';
|
import APIClient, { AxiosClientWithError } from './index';
|
||||||
|
|
||||||
export const getDashboardVersions: Function = (
|
export const getDashboardVersions: Function = (
|
||||||
id: string
|
id: string
|
||||||
@ -63,7 +63,7 @@ export const getAllDashboards = (
|
|||||||
`${searchParams.toString()}${paging ? `&${paging}` : ''}`
|
`${searchParams.toString()}${paging ? `&${paging}` : ''}`
|
||||||
);
|
);
|
||||||
|
|
||||||
return APIClient.get(url);
|
return AxiosClientWithError.get(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getDashboardDetails: Function = (
|
export const getDashboardDetails: Function = (
|
||||||
|
@ -12,9 +12,33 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import jsonData from '../jsons/en';
|
||||||
|
import { showErrorToast } from '../utils/ToastUtils';
|
||||||
|
|
||||||
|
const baseURL = '/api/v1';
|
||||||
|
|
||||||
const axiosClient = axios.create({
|
const axiosClient = axios.create({
|
||||||
baseURL: '/api/v1',
|
baseURL,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const AxiosClientWithError = axios.create({
|
||||||
|
baseURL,
|
||||||
|
});
|
||||||
|
|
||||||
|
AxiosClientWithError.interceptors.response.use(
|
||||||
|
(response) => {
|
||||||
|
if (response.data) {
|
||||||
|
return Promise.resolve(response);
|
||||||
|
} else {
|
||||||
|
throw null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
showErrorToast(
|
||||||
|
error,
|
||||||
|
jsonData['api-error-messages']['unexpected-server-response']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
export default axiosClient;
|
export default axiosClient;
|
||||||
|
@ -15,7 +15,7 @@ import { AxiosResponse } from 'axios';
|
|||||||
import { isNil } from 'lodash';
|
import { isNil } from 'lodash';
|
||||||
import { Pipeline } from '../generated/entity/data/pipeline';
|
import { Pipeline } from '../generated/entity/data/pipeline';
|
||||||
import { getURLWithQueryFields } from '../utils/APIUtils';
|
import { getURLWithQueryFields } from '../utils/APIUtils';
|
||||||
import APIClient from './index';
|
import APIClient, { AxiosClientWithError } from './index';
|
||||||
|
|
||||||
export const getPipelineVersions: Function = (
|
export const getPipelineVersions: Function = (
|
||||||
id: string
|
id: string
|
||||||
@ -63,7 +63,7 @@ export const getAllPipelines = (
|
|||||||
`${searchParams.toString()}${paging ? `&${paging}` : ''}`
|
`${searchParams.toString()}${paging ? `&${paging}` : ''}`
|
||||||
);
|
);
|
||||||
|
|
||||||
return APIClient.get(url);
|
return AxiosClientWithError.get(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPipelineDetails: Function = (
|
export const getPipelineDetails: Function = (
|
||||||
|
@ -19,7 +19,7 @@ import { CreateTableTest } from '../generated/api/tests/createTableTest';
|
|||||||
import { ColumnTestType } from '../generated/entity/data/table';
|
import { ColumnTestType } from '../generated/entity/data/table';
|
||||||
import { TableTestType } from '../generated/tests/tableTest';
|
import { TableTestType } from '../generated/tests/tableTest';
|
||||||
import { getURLWithQueryFields } from '../utils/APIUtils';
|
import { getURLWithQueryFields } from '../utils/APIUtils';
|
||||||
import APIClient from './index';
|
import APIClient, { AxiosClientWithError } from './index';
|
||||||
|
|
||||||
export const getTableDetails: Function = (
|
export const getTableDetails: Function = (
|
||||||
id: string,
|
id: string,
|
||||||
@ -76,7 +76,7 @@ export const getAllTables = (
|
|||||||
searchParams.toString()
|
searchParams.toString()
|
||||||
);
|
);
|
||||||
|
|
||||||
return APIClient.get(url);
|
return AxiosClientWithError.get(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getDatabaseTables: Function = (
|
export const getDatabaseTables: Function = (
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
import { AxiosResponse } from 'axios';
|
import { AxiosResponse } from 'axios';
|
||||||
import { Team } from 'Models';
|
import { Team } from 'Models';
|
||||||
import { getURLWithQueryFields } from '../utils/APIUtils';
|
import { getURLWithQueryFields } from '../utils/APIUtils';
|
||||||
import APIClient from './index';
|
import APIClient, { AxiosClientWithError } from './index';
|
||||||
|
|
||||||
export const getTeams = (
|
export const getTeams = (
|
||||||
arrQueryFields?: string | string[],
|
arrQueryFields?: string | string[],
|
||||||
@ -22,7 +22,9 @@ export const getTeams = (
|
|||||||
): Promise<AxiosResponse> => {
|
): Promise<AxiosResponse> => {
|
||||||
const url = getURLWithQueryFields('/teams', arrQueryFields);
|
const url = getURLWithQueryFields('/teams', arrQueryFields);
|
||||||
|
|
||||||
return APIClient.get(`${url}${arrQueryFields ? '&' : '?'}limit=${limit}`);
|
return AxiosClientWithError.get(
|
||||||
|
`${url}${arrQueryFields ? '&' : '?'}limit=${limit}`
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getTeamByName: Function = (
|
export const getTeamByName: Function = (
|
||||||
|
@ -15,7 +15,7 @@ import { AxiosResponse } from 'axios';
|
|||||||
import { isNil } from 'lodash';
|
import { isNil } from 'lodash';
|
||||||
import { Topic } from 'Models';
|
import { Topic } from 'Models';
|
||||||
import { getURLWithQueryFields } from '../utils/APIUtils';
|
import { getURLWithQueryFields } from '../utils/APIUtils';
|
||||||
import APIClient from './index';
|
import APIClient, { AxiosClientWithError } from './index';
|
||||||
|
|
||||||
export const getTopicVersions: Function = (
|
export const getTopicVersions: Function = (
|
||||||
id: string
|
id: string
|
||||||
@ -63,7 +63,7 @@ export const getAllTopics = (
|
|||||||
`${searchParams.toString()}${paging ? `&${paging}` : ''}`
|
`${searchParams.toString()}${paging ? `&${paging}` : ''}`
|
||||||
);
|
);
|
||||||
|
|
||||||
return APIClient.get(url);
|
return AxiosClientWithError.get(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getTopicDetails: Function = (
|
export const getTopicDetails: Function = (
|
||||||
|
@ -19,7 +19,7 @@ import { SearchIndex } from '../enums/search.enum';
|
|||||||
import { CreateUser } from '../generated/api/teams/createUser';
|
import { CreateUser } from '../generated/api/teams/createUser';
|
||||||
import { User } from '../generated/entity/teams/user';
|
import { User } from '../generated/entity/teams/user';
|
||||||
import { getURLWithQueryFields } from '../utils/APIUtils';
|
import { getURLWithQueryFields } from '../utils/APIUtils';
|
||||||
import APIClient from './index';
|
import APIClient, { AxiosClientWithError } from './index';
|
||||||
|
|
||||||
export const getUsers = (
|
export const getUsers = (
|
||||||
arrQueryFields?: string,
|
arrQueryFields?: string,
|
||||||
@ -41,7 +41,7 @@ export const getUsers = (
|
|||||||
? `${arrQueryFields?.length || qParam ? '&' : '?'}limit=${limit}`
|
? `${arrQueryFields?.length || qParam ? '&' : '?'}limit=${limit}`
|
||||||
: '');
|
: '');
|
||||||
|
|
||||||
return APIClient.get(url);
|
return AxiosClientWithError.get(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateUserDetail = (
|
export const updateUserDetail = (
|
||||||
|
@ -97,11 +97,7 @@ const Users = ({
|
|||||||
const fetchTeams = () => {
|
const fetchTeams = () => {
|
||||||
getTeams(['users'])
|
getTeams(['users'])
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
if (res.data) {
|
setTeams(res.data.data);
|
||||||
setTeams(res.data.data);
|
|
||||||
} else {
|
|
||||||
throw jsonData['api-error-messages']['unexpected-server-response'];
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
showErrorToast(
|
showErrorToast(
|
||||||
|
@ -43,11 +43,7 @@ const CreateUserPage = () => {
|
|||||||
const fetchTeams = () => {
|
const fetchTeams = () => {
|
||||||
getTeams('defaultRoles')
|
getTeams('defaultRoles')
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
if (res.data) {
|
setTeams(res.data.data);
|
||||||
setTeams(res.data.data);
|
|
||||||
} else {
|
|
||||||
throw jsonData['api-error-messages']['unexpected-server-response'];
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
showErrorToast(
|
showErrorToast(
|
||||||
|
@ -96,11 +96,7 @@ const MyDataPage = () => {
|
|||||||
// limit=0 will fetch empty data list with total count
|
// limit=0 will fetch empty data list with total count
|
||||||
getAllTables('', 0)
|
getAllTables('', 0)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.data) {
|
setTableCount(res.data.paging.total);
|
||||||
setTableCount(res.data.paging.total);
|
|
||||||
} else {
|
|
||||||
throw jsonData['api-error-messages']['unexpected-server-response'];
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
showErrorToast(
|
showErrorToast(
|
||||||
@ -113,11 +109,7 @@ const MyDataPage = () => {
|
|||||||
// limit=0 will fetch empty data list with total count
|
// limit=0 will fetch empty data list with total count
|
||||||
getAllTopics('', '', 0)
|
getAllTopics('', '', 0)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.data) {
|
setTopicCount(res.data.paging.total);
|
||||||
setTopicCount(res.data.paging.total);
|
|
||||||
} else {
|
|
||||||
throw jsonData['api-error-messages']['unexpected-server-response'];
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
showErrorToast(
|
showErrorToast(
|
||||||
@ -130,11 +122,7 @@ const MyDataPage = () => {
|
|||||||
// limit=0 will fetch empty data list with total count
|
// limit=0 will fetch empty data list with total count
|
||||||
getAllPipelines('', '', 0)
|
getAllPipelines('', '', 0)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.data) {
|
setPipelineCount(res.data.paging.total);
|
||||||
setPipelineCount(res.data.paging.total);
|
|
||||||
} else {
|
|
||||||
throw jsonData['api-error-messages']['unexpected-server-response'];
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
showErrorToast(
|
showErrorToast(
|
||||||
@ -147,11 +135,7 @@ const MyDataPage = () => {
|
|||||||
// limit=0 will fetch empty data list with total count
|
// limit=0 will fetch empty data list with total count
|
||||||
getAllDashboards('', '', 0)
|
getAllDashboards('', '', 0)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.data) {
|
setDashboardCount(res.data.paging.total);
|
||||||
setDashboardCount(res.data.paging.total);
|
|
||||||
} else {
|
|
||||||
throw jsonData['api-error-messages']['unexpected-server-response'];
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
showErrorToast(
|
showErrorToast(
|
||||||
@ -165,11 +149,7 @@ const MyDataPage = () => {
|
|||||||
const fetchTeamsAndUsersCount = () => {
|
const fetchTeamsAndUsersCount = () => {
|
||||||
getUsers('', 0)
|
getUsers('', 0)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.data) {
|
setUserCount(res.data.paging.total);
|
||||||
setUserCount(res.data.paging.total);
|
|
||||||
} else {
|
|
||||||
throw jsonData['api-error-messages']['unexpected-server-response'];
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
showErrorToast(
|
showErrorToast(
|
||||||
@ -181,11 +161,7 @@ const MyDataPage = () => {
|
|||||||
|
|
||||||
getTeams('', 0)
|
getTeams('', 0)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.data) {
|
setTeamCount(res.data.paging.total);
|
||||||
setTeamCount(res.data.paging.total);
|
|
||||||
} else {
|
|
||||||
throw jsonData['api-error-messages']['unexpected-server-response'];
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
showErrorToast(
|
showErrorToast(
|
||||||
|
@ -216,11 +216,7 @@ const RolesPage = () => {
|
|||||||
const fetchTeams = () => {
|
const fetchTeams = () => {
|
||||||
getTeams('defaultRoles')
|
getTeams('defaultRoles')
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
if (res.data) {
|
setTeamList(res.data.data);
|
||||||
setTeamList(res.data.data);
|
|
||||||
} else {
|
|
||||||
throw jsonData['api-error-messages']['unexpected-server-response'];
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
showErrorToast(
|
showErrorToast(
|
||||||
|
@ -206,10 +206,8 @@ const TeamsAndUsersPage = () => {
|
|||||||
setIsTeamMemberLoading(true);
|
setIsTeamMemberLoading(true);
|
||||||
getUsers('', PAGE_SIZE_MEDIUM, { team, ...pagin })
|
getUsers('', PAGE_SIZE_MEDIUM, { team, ...pagin })
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
if (res.data) {
|
setCurrentTeamUsers(res.data.data);
|
||||||
setCurrentTeamUsers(res.data.data);
|
setTeamUserPagin(res.data.paging);
|
||||||
setTeamUserPagin(res.data.paging);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setCurrentTeamUsers([]);
|
setCurrentTeamUsers([]);
|
||||||
@ -224,17 +222,13 @@ const TeamsAndUsersPage = () => {
|
|||||||
const fetchTeams = () => {
|
const fetchTeams = () => {
|
||||||
getTeams(['users', 'owns', 'defaultRoles', 'owner'])
|
getTeams(['users', 'owns', 'defaultRoles', 'owner'])
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
if (res.data) {
|
if (!teamAndUser && res.data.data.length > 0) {
|
||||||
if (!teamAndUser && res.data.data.length > 0) {
|
getCurrentTeamUsers(res.data.data[0].name);
|
||||||
getCurrentTeamUsers(res.data.data[0].name);
|
setCurrentTeam(res.data.data[0]);
|
||||||
setCurrentTeam(res.data.data[0]);
|
setIsRightPannelLoading(false);
|
||||||
setIsRightPannelLoading(false);
|
|
||||||
}
|
|
||||||
setTeams(res.data.data);
|
|
||||||
AppState.updateUserTeam(res.data.data);
|
|
||||||
} else {
|
|
||||||
throw jsonData['api-error-messages']['unexpected-server-response'];
|
|
||||||
}
|
}
|
||||||
|
setTeams(res.data.data);
|
||||||
|
AppState.updateUserTeam(res.data.data);
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
const errMsg = getErrorText(
|
const errMsg = getErrorText(
|
||||||
@ -255,13 +249,9 @@ const TeamsAndUsersPage = () => {
|
|||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
getUsers('profile,teams,roles', API_RES_MAX_SIZE)
|
getUsers('profile,teams,roles', API_RES_MAX_SIZE)
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
if (res.data) {
|
const resUsers = res.data.data;
|
||||||
const resUsers = res.data.data;
|
setUserList(resUsers);
|
||||||
setUserList(resUsers);
|
resolve();
|
||||||
resolve();
|
|
||||||
} else {
|
|
||||||
throw jsonData['api-error-messages']['unexpected-server-response'];
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
const errMsg = getErrorText(
|
const errMsg = getErrorText(
|
||||||
|
@ -41,11 +41,7 @@ const UserListPage = () => {
|
|||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
getTeams(['users'])
|
getTeams(['users'])
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
if (res.data) {
|
setTeams(res.data.data);
|
||||||
setTeams(res.data.data);
|
|
||||||
} else {
|
|
||||||
throw jsonData['api-error-messages']['unexpected-server-response'];
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
showErrorToast(
|
showErrorToast(
|
||||||
|
@ -129,15 +129,11 @@ const TeamsPage = () => {
|
|||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
getTeams(['users', 'owns', 'defaultRoles', 'owner'])
|
getTeams(['users', 'owns', 'defaultRoles', 'owner'])
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
if (res.data) {
|
if (!team) {
|
||||||
if (!team) {
|
setCurrentTeam(res.data.data[0]);
|
||||||
setCurrentTeam(res.data.data[0]);
|
|
||||||
}
|
|
||||||
setTeams(res.data.data);
|
|
||||||
AppState.updateUserTeam(res.data.data);
|
|
||||||
} else {
|
|
||||||
throw jsonData['api-error-messages']['unexpected-server-response'];
|
|
||||||
}
|
}
|
||||||
|
setTeams(res.data.data);
|
||||||
|
AppState.updateUserTeam(res.data.data);
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
const errMsg = getErrorText(
|
const errMsg = getErrorText(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user