Revert " [issue 5222] remove redundant code used to check API response (#5223)" (#5242)

This reverts commit 1df1df616f50cf96553a99efaf77e300deeb6989.
This commit is contained in:
Vivek Ratnavel Subramanian 2022-05-31 15:25:36 -07:00 committed by GitHub
parent db0eaa8cbb
commit ae35909692
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 92 additions and 64 deletions

View File

@ -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, { AxiosClientWithError } from './index';
import APIClient from './index';
export const getDashboardVersions: Function = (
id: string
@ -63,7 +63,7 @@ export const getAllDashboards = (
`${searchParams.toString()}${paging ? `&${paging}` : ''}`
);
return AxiosClientWithError.get(url);
return APIClient.get(url);
};
export const getDashboardDetails: Function = (

View File

@ -12,33 +12,9 @@
*/
import axios from 'axios';
import jsonData from '../jsons/en';
import { showErrorToast } from '../utils/ToastUtils';
const baseURL = '/api/v1';
const axiosClient = axios.create({
baseURL,
baseURL: '/api/v1',
});
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;

View File

@ -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, { AxiosClientWithError } from './index';
import APIClient from './index';
export const getPipelineVersions: Function = (
id: string
@ -63,7 +63,7 @@ export const getAllPipelines = (
`${searchParams.toString()}${paging ? `&${paging}` : ''}`
);
return AxiosClientWithError.get(url);
return APIClient.get(url);
};
export const getPipelineDetails: Function = (

View File

@ -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, { AxiosClientWithError } from './index';
import APIClient from './index';
export const getTableDetails: Function = (
id: string,
@ -76,7 +76,7 @@ export const getAllTables = (
searchParams.toString()
);
return AxiosClientWithError.get(url);
return APIClient.get(url);
};
export const getDatabaseTables: Function = (

View File

@ -14,7 +14,7 @@
import { AxiosResponse } from 'axios';
import { Team } from 'Models';
import { getURLWithQueryFields } from '../utils/APIUtils';
import APIClient, { AxiosClientWithError } from './index';
import APIClient from './index';
export const getTeams = (
arrQueryFields?: string | string[],
@ -22,9 +22,7 @@ export const getTeams = (
): Promise<AxiosResponse> => {
const url = getURLWithQueryFields('/teams', arrQueryFields);
return AxiosClientWithError.get(
`${url}${arrQueryFields ? '&' : '?'}limit=${limit}`
);
return APIClient.get(`${url}${arrQueryFields ? '&' : '?'}limit=${limit}`);
};
export const getTeamByName: Function = (

View File

@ -15,7 +15,7 @@ import { AxiosResponse } from 'axios';
import { isNil } from 'lodash';
import { Topic } from 'Models';
import { getURLWithQueryFields } from '../utils/APIUtils';
import APIClient, { AxiosClientWithError } from './index';
import APIClient from './index';
export const getTopicVersions: Function = (
id: string
@ -63,7 +63,7 @@ export const getAllTopics = (
`${searchParams.toString()}${paging ? `&${paging}` : ''}`
);
return AxiosClientWithError.get(url);
return APIClient.get(url);
};
export const getTopicDetails: Function = (

View File

@ -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, { AxiosClientWithError } from './index';
import APIClient from './index';
export const getUsers = (
arrQueryFields?: string,
@ -41,7 +41,7 @@ export const getUsers = (
? `${arrQueryFields?.length || qParam ? '&' : '?'}limit=${limit}`
: '');
return AxiosClientWithError.get(url);
return APIClient.get(url);
};
export const updateUserDetail = (

View File

@ -97,7 +97,11 @@ 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'];
}
})
.catch((err: AxiosError) => {
showErrorToast(

View File

@ -43,7 +43,11 @@ 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'];
}
})
.catch((err: AxiosError) => {
showErrorToast(

View File

@ -96,7 +96,11 @@ 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'];
}
})
.catch((err: AxiosError) => {
showErrorToast(
@ -109,7 +113,11 @@ 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'];
}
})
.catch((err: AxiosError) => {
showErrorToast(
@ -122,7 +130,11 @@ 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'];
}
})
.catch((err: AxiosError) => {
showErrorToast(
@ -135,7 +147,11 @@ 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'];
}
})
.catch((err: AxiosError) => {
showErrorToast(
@ -149,7 +165,11 @@ 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'];
}
})
.catch((err: AxiosError) => {
showErrorToast(
@ -161,7 +181,11 @@ const MyDataPage = () => {
getTeams('', 0)
.then((res) => {
if (res.data) {
setTeamCount(res.data.paging.total);
} else {
throw jsonData['api-error-messages']['unexpected-server-response'];
}
})
.catch((err: AxiosError) => {
showErrorToast(

View File

@ -216,7 +216,11 @@ 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'];
}
})
.catch((err: AxiosError) => {
showErrorToast(

View File

@ -206,8 +206,10 @@ const TeamsAndUsersPage = () => {
setIsTeamMemberLoading(true);
getUsers('', PAGE_SIZE_MEDIUM, { team, ...pagin })
.then((res: AxiosResponse) => {
if (res.data) {
setCurrentTeamUsers(res.data.data);
setTeamUserPagin(res.data.paging);
}
})
.catch(() => {
setCurrentTeamUsers([]);
@ -222,6 +224,7 @@ 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]);
@ -229,6 +232,9 @@ const TeamsAndUsersPage = () => {
}
setTeams(res.data.data);
AppState.updateUserTeam(res.data.data);
} else {
throw jsonData['api-error-messages']['unexpected-server-response'];
}
})
.catch((err: AxiosError) => {
const errMsg = getErrorText(
@ -249,9 +255,13 @@ 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'];
}
})
.catch((err: AxiosError) => {
const errMsg = getErrorText(

View File

@ -41,7 +41,11 @@ 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'];
}
})
.catch((err: AxiosError) => {
showErrorToast(

View File

@ -129,11 +129,15 @@ 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'];
}
})
.catch((err: AxiosError) => {
const errMsg = getErrorText(