From 52c53a49b9454f5a53fac239d0ccf01c89f4f5fb Mon Sep 17 00:00:00 2001 From: Pavel Lorenz Date: Fri, 17 Mar 2023 11:21:39 +0100 Subject: [PATCH 1/3] fix: rewrite statusText check to status value --- src/modules/auth/clients/ClientCreateContainer.js | 8 ++++---- src/modules/auth/clients/ClientDetailContainer.js | 6 +++--- src/modules/auth/clients/ClientListContainer.js | 2 +- src/modules/auth/tenant/TenantDetailContainer.js | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/modules/auth/clients/ClientCreateContainer.js b/src/modules/auth/clients/ClientCreateContainer.js index cc0eb1d6..9b9d33dd 100644 --- a/src/modules/auth/clients/ClientCreateContainer.js +++ b/src/modules/auth/clients/ClientCreateContainer.js @@ -113,7 +113,7 @@ const ClientCreateContainer = (props) => { const retrieveClientFeatures = async () => { try { let response = await SeaCatAuthAPI.get('/client/features'); - if (response.statusText != 'OK') { + if (response.status !== 200) { throw new Error("Unable to get clients"); } setMetaData(response.data["metadata_schema"]); @@ -127,7 +127,7 @@ const ClientCreateContainer = (props) => { const getClientDetail = async () => { try { let response = await SeaCatAuthAPI.get(`client/${client_id}`); - if (response.statusText != 'OK') { + if (response.status !== 200) { throw new Error("Unable to get client details"); } setClient(response.data); @@ -142,7 +142,7 @@ const ClientCreateContainer = (props) => { let body = refactorSubmitData(values, "create"); try { let response = await SeaCatAuthAPI.post(`/client`, body); - if (response.statusText != 'OK') { + if (response.status !== 200) { throw new Error("Unable to create client"); } if (response.data?.client_id) { @@ -160,7 +160,7 @@ const ClientCreateContainer = (props) => { setDisabled(true); try { let response = await SeaCatAuthAPI.put(`/client/${client_id}`, body); - if (response.statusText != 'OK') { + if (response.status !== 200) { throw new Error("Unable to change client details"); } setDisabled(false); diff --git a/src/modules/auth/clients/ClientDetailContainer.js b/src/modules/auth/clients/ClientDetailContainer.js index 50f7cc44..a1522e9b 100644 --- a/src/modules/auth/clients/ClientDetailContainer.js +++ b/src/modules/auth/clients/ClientDetailContainer.js @@ -30,7 +30,7 @@ const ClientDetailContainer = (props) => { const getClientDetail = async () => { try { let response = await SeaCatAuthAPI.get(`client/${client_id}`); - if (response.statusText != 'OK') { + if (response.status !== 200) { throw new Error("Unable to get client details"); } setClient(response.data); @@ -43,7 +43,7 @@ const ClientDetailContainer = (props) => { const resetSecret = async () => { try { let response = await SeaCatAuthAPI.post(`client/${client_id}/reset_secret`); - if (response.statusText != 'OK') { + if (response.status !== 200) { throw new Error("Unable to reset client secret"); } props.app.addAlert("success", t('ClientDetailContainer|Secret has been reset successfully')); @@ -73,7 +73,7 @@ const ClientDetailContainer = (props) => { const removeClient = async () => { try { let response = await SeaCatAuthAPI.delete(`/client/${client_id}`); - if (response.statusText != 'OK') { + if (response.status !== 200) { throw new Error("Unable to delete client"); } props.app.addAlert("success", t('ClientDetailContainer|Client removed successfully')); diff --git a/src/modules/auth/clients/ClientListContainer.js b/src/modules/auth/clients/ClientListContainer.js index bdfb9c95..eb952297 100644 --- a/src/modules/auth/clients/ClientListContainer.js +++ b/src/modules/auth/clients/ClientListContainer.js @@ -77,7 +77,7 @@ function ClientListContainer(props) { const retrieveData = async () => { try { let response = await SeaCatAuthAPI.get("/client", {params: {p:page, i: limit, f: filter}}); - if (response.statusText != 'OK') { + if (response.status !== 200) { throw new Error("Unable to get clients"); } setData(response.data.data); diff --git a/src/modules/auth/tenant/TenantDetailContainer.js b/src/modules/auth/tenant/TenantDetailContainer.js index 22040386..0346ccfc 100644 --- a/src/modules/auth/tenant/TenantDetailContainer.js +++ b/src/modules/auth/tenant/TenantDetailContainer.js @@ -127,7 +127,7 @@ function TenantDetailContainer(props) { const retrieveData = async () => { try { let response = await SeaCatAuthAPI.get(`/tenant/${tenant_id}`); - if (response.statusText !== "OK") { + if (response.status !== 200) { throw new Error(t("TenantDetailContainer|Something went wrong, failed to fetch tenant detail")); } setData(response.data); From b39f15498f25e921a817a48e1ec5a55aa612d5f5 Mon Sep 17 00:00:00 2001 From: Pavel Lorenz Date: Wed, 22 Mar 2023 08:44:40 +0100 Subject: [PATCH 2/3] fix: refactor of response check --- src/modules/auth/clients/ClientCreateContainer.js | 11 +---------- src/modules/auth/clients/ClientDetailContainer.js | 8 +------- src/modules/auth/clients/ClientListContainer.js | 3 --- src/modules/auth/tenant/TenantDetailContainer.js | 3 --- 4 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/modules/auth/clients/ClientCreateContainer.js b/src/modules/auth/clients/ClientCreateContainer.js index 9b9d33dd..5373ff35 100644 --- a/src/modules/auth/clients/ClientCreateContainer.js +++ b/src/modules/auth/clients/ClientCreateContainer.js @@ -113,9 +113,6 @@ const ClientCreateContainer = (props) => { const retrieveClientFeatures = async () => { try { let response = await SeaCatAuthAPI.get('/client/features'); - if (response.status !== 200) { - throw new Error("Unable to get clients"); - } setMetaData(response.data["metadata_schema"]); setTemplate(response.data["templates"]); } catch (e) { @@ -127,9 +124,6 @@ const ClientCreateContainer = (props) => { const getClientDetail = async () => { try { let response = await SeaCatAuthAPI.get(`client/${client_id}`); - if (response.status !== 200) { - throw new Error("Unable to get client details"); - } setClient(response.data); } catch (e) { console.error(e); @@ -142,9 +136,6 @@ const ClientCreateContainer = (props) => { let body = refactorSubmitData(values, "create"); try { let response = await SeaCatAuthAPI.post(`/client`, body); - if (response.status !== 200) { - throw new Error("Unable to create client"); - } if (response.data?.client_id) { props.app.addAlert("success", t("ClientCreateContainer|Client has been created")); props.history.push(`/auth/clients/${response.data.client_id}`); @@ -160,7 +151,7 @@ const ClientCreateContainer = (props) => { setDisabled(true); try { let response = await SeaCatAuthAPI.put(`/client/${client_id}`, body); - if (response.status !== 200) { + if (response.data.result !== "OK") { throw new Error("Unable to change client details"); } setDisabled(false); diff --git a/src/modules/auth/clients/ClientDetailContainer.js b/src/modules/auth/clients/ClientDetailContainer.js index a1522e9b..4d2027ae 100644 --- a/src/modules/auth/clients/ClientDetailContainer.js +++ b/src/modules/auth/clients/ClientDetailContainer.js @@ -30,9 +30,6 @@ const ClientDetailContainer = (props) => { const getClientDetail = async () => { try { let response = await SeaCatAuthAPI.get(`client/${client_id}`); - if (response.status !== 200) { - throw new Error("Unable to get client details"); - } setClient(response.data); } catch (e) { console.error(e); @@ -43,9 +40,6 @@ const ClientDetailContainer = (props) => { const resetSecret = async () => { try { let response = await SeaCatAuthAPI.post(`client/${client_id}/reset_secret`); - if (response.status !== 200) { - throw new Error("Unable to reset client secret"); - } props.app.addAlert("success", t('ClientDetailContainer|Secret has been reset successfully')); getClientDetail(); } catch (e) { @@ -73,7 +67,7 @@ const ClientDetailContainer = (props) => { const removeClient = async () => { try { let response = await SeaCatAuthAPI.delete(`/client/${client_id}`); - if (response.status !== 200) { + if (response.data.result !== "OK") { throw new Error("Unable to delete client"); } props.app.addAlert("success", t('ClientDetailContainer|Client removed successfully')); diff --git a/src/modules/auth/clients/ClientListContainer.js b/src/modules/auth/clients/ClientListContainer.js index eb952297..2304a557 100644 --- a/src/modules/auth/clients/ClientListContainer.js +++ b/src/modules/auth/clients/ClientListContainer.js @@ -77,9 +77,6 @@ function ClientListContainer(props) { const retrieveData = async () => { try { let response = await SeaCatAuthAPI.get("/client", {params: {p:page, i: limit, f: filter}}); - if (response.status !== 200) { - throw new Error("Unable to get clients"); - } setData(response.data.data); setCount(response.data.count); setLoading(false); diff --git a/src/modules/auth/tenant/TenantDetailContainer.js b/src/modules/auth/tenant/TenantDetailContainer.js index 0346ccfc..55d6e3a9 100644 --- a/src/modules/auth/tenant/TenantDetailContainer.js +++ b/src/modules/auth/tenant/TenantDetailContainer.js @@ -127,9 +127,6 @@ function TenantDetailContainer(props) { const retrieveData = async () => { try { let response = await SeaCatAuthAPI.get(`/tenant/${tenant_id}`); - if (response.status !== 200) { - throw new Error(t("TenantDetailContainer|Something went wrong, failed to fetch tenant detail")); - } setData(response.data); response.data?.data && setCustomTenantData(response.data.data); setLoadingCustomData(false); From a14f6e182f14b0c34f8e8025013481fd83c426aa Mon Sep 17 00:00:00 2001 From: fpesek Date: Wed, 22 Mar 2023 10:00:49 +0100 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3c8b068..47aa8908 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ - Webpack V4 to V5 migration. (INDIGO Sprint 230303, [!16](https://github.com/TeskaLabs/seacat-admin-webui/pull/16)) +### Bugfix + +- Fix responses in Clients and Tenant containers causing errors on undefined value. Closing issue [!24](https://github.com/TeskaLabs/seacat-admin-webui/issues/24). (INDIGO Sprint 230317, [!25](https://github.com/TeskaLabs/seacat-admin-webui/pull/25)) + ## v23.5 ### Features