diff --git a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/dashboardAPI.ts b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/dashboardAPI.ts index 9d508c86957..1336e906cc3 100644 --- a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/dashboardAPI.ts +++ b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/dashboardAPI.ts @@ -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 = ( diff --git a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/index.js b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/index.js index 9a89dc3fc00..97dc96f56bf 100644 --- a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/index.js +++ b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/index.js @@ -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; diff --git a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/pipelineAPI.ts b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/pipelineAPI.ts index 5f0e5d87435..5685a18f1c6 100644 --- a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/pipelineAPI.ts +++ b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/pipelineAPI.ts @@ -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 = ( diff --git a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/tableAPI.ts b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/tableAPI.ts index 2544d61e9bf..4bec0ba708b 100644 --- a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/tableAPI.ts +++ b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/tableAPI.ts @@ -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 = ( diff --git a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/teamsAPI.ts b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/teamsAPI.ts index 5561cbbd22b..e3dd1072d06 100644 --- a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/teamsAPI.ts +++ b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/teamsAPI.ts @@ -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 => { const url = getURLWithQueryFields('/teams', arrQueryFields); - return AxiosClientWithError.get( - `${url}${arrQueryFields ? '&' : '?'}limit=${limit}` - ); + return APIClient.get(`${url}${arrQueryFields ? '&' : '?'}limit=${limit}`); }; export const getTeamByName: Function = ( diff --git a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/topicsAPI.ts b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/topicsAPI.ts index 3089f199121..34871c5c80a 100644 --- a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/topicsAPI.ts +++ b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/topicsAPI.ts @@ -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 = ( diff --git a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/userAPI.ts b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/userAPI.ts index c6f7ac49c54..18d5d364489 100644 --- a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/userAPI.ts +++ b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/userAPI.ts @@ -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 = ( diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Users/Users.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Users/Users.component.tsx index 7af0d47cd88..68aa9c8a5ad 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Users/Users.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Users/Users.component.tsx @@ -97,7 +97,11 @@ const Users = ({ const fetchTeams = () => { getTeams(['users']) .then((res: AxiosResponse) => { - setTeams(res.data.data); + if (res.data) { + setTeams(res.data.data); + } else { + throw jsonData['api-error-messages']['unexpected-server-response']; + } }) .catch((err: AxiosError) => { showErrorToast( diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/CreateUserPage/CreateUserPage.component.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/CreateUserPage/CreateUserPage.component.tsx index 4f1e7952863..e38da50e5a1 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/CreateUserPage/CreateUserPage.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/CreateUserPage/CreateUserPage.component.tsx @@ -43,7 +43,11 @@ const CreateUserPage = () => { const fetchTeams = () => { getTeams('defaultRoles') .then((res: AxiosResponse) => { - setTeams(res.data.data); + if (res.data) { + setTeams(res.data.data); + } else { + throw jsonData['api-error-messages']['unexpected-server-response']; + } }) .catch((err: AxiosError) => { showErrorToast( diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/MyDataPage/MyDataPage.component.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/MyDataPage/MyDataPage.component.tsx index 2eafb7430a2..a08f862027e 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/MyDataPage/MyDataPage.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/MyDataPage/MyDataPage.component.tsx @@ -96,7 +96,11 @@ const MyDataPage = () => { // limit=0 will fetch empty data list with total count getAllTables('', 0) .then((res) => { - setTableCount(res.data.paging.total); + 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) => { - setTopicCount(res.data.paging.total); + 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) => { - setPipelineCount(res.data.paging.total); + 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) => { - setDashboardCount(res.data.paging.total); + 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) => { - setUserCount(res.data.paging.total); + 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) => { - setTeamCount(res.data.paging.total); + if (res.data) { + setTeamCount(res.data.paging.total); + } else { + throw jsonData['api-error-messages']['unexpected-server-response']; + } }) .catch((err: AxiosError) => { showErrorToast( diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/RolesPage/RolesPage.component.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/RolesPage/RolesPage.component.tsx index 5edccda95a2..c51ed76ff75 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/RolesPage/RolesPage.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/RolesPage/RolesPage.component.tsx @@ -216,7 +216,11 @@ const RolesPage = () => { const fetchTeams = () => { getTeams('defaultRoles') .then((res: AxiosResponse) => { - setTeamList(res.data.data); + if (res.data) { + setTeamList(res.data.data); + } else { + throw jsonData['api-error-messages']['unexpected-server-response']; + } }) .catch((err: AxiosError) => { showErrorToast( diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/TeamsAndUsersPage/TeamsAndUsersPage.component.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/TeamsAndUsersPage/TeamsAndUsersPage.component.tsx index c815126f633..14417acdb7b 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/TeamsAndUsersPage/TeamsAndUsersPage.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/TeamsAndUsersPage/TeamsAndUsersPage.component.tsx @@ -206,8 +206,10 @@ const TeamsAndUsersPage = () => { setIsTeamMemberLoading(true); getUsers('', PAGE_SIZE_MEDIUM, { team, ...pagin }) .then((res: AxiosResponse) => { - setCurrentTeamUsers(res.data.data); - setTeamUserPagin(res.data.paging); + if (res.data) { + setCurrentTeamUsers(res.data.data); + setTeamUserPagin(res.data.paging); + } }) .catch(() => { setCurrentTeamUsers([]); @@ -222,13 +224,17 @@ const TeamsAndUsersPage = () => { const fetchTeams = () => { getTeams(['users', 'owns', 'defaultRoles', 'owner']) .then((res: AxiosResponse) => { - if (!teamAndUser && res.data.data.length > 0) { - getCurrentTeamUsers(res.data.data[0].name); - setCurrentTeam(res.data.data[0]); - setIsRightPannelLoading(false); + 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']; } - setTeams(res.data.data); - AppState.updateUserTeam(res.data.data); }) .catch((err: AxiosError) => { const errMsg = getErrorText( @@ -249,9 +255,13 @@ const TeamsAndUsersPage = () => { return new Promise((resolve, reject) => { getUsers('profile,teams,roles', API_RES_MAX_SIZE) .then((res: AxiosResponse) => { - const resUsers = res.data.data; - setUserList(resUsers); - resolve(); + 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( diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/UserListPage/UserListPage.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/UserListPage/UserListPage.tsx index 26f5aecc919..cf58290a020 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/UserListPage/UserListPage.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/UserListPage/UserListPage.tsx @@ -41,7 +41,11 @@ const UserListPage = () => { setIsLoading(true); getTeams(['users']) .then((res: AxiosResponse) => { - setTeams(res.data.data); + if (res.data) { + setTeams(res.data.data); + } else { + throw jsonData['api-error-messages']['unexpected-server-response']; + } }) .catch((err: AxiosError) => { showErrorToast( diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/teams/index.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/teams/index.tsx index 4f3e7cf1ec5..85cf489cbc0 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/teams/index.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/teams/index.tsx @@ -129,11 +129,15 @@ const TeamsPage = () => { setIsLoading(true); getTeams(['users', 'owns', 'defaultRoles', 'owner']) .then((res: AxiosResponse) => { - if (!team) { - setCurrentTeam(res.data.data[0]); + 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']; } - setTeams(res.data.data); - AppState.updateUserTeam(res.data.data); }) .catch((err: AxiosError) => { const errMsg = getErrorText(