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