From fb59f0f8fce95f99411b5148c93d92eb23a1eb21 Mon Sep 17 00:00:00 2001 From: RAKHI DUTTA Date: Tue, 12 Aug 2025 11:33:55 +0530 Subject: [PATCH 1/5] issue 668 Signed-off-by: RAKHI DUTTA --- mcpgateway/static/admin.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mcpgateway/static/admin.js b/mcpgateway/static/admin.js index 73bb501ec..e2b2da4da 100644 --- a/mcpgateway/static/admin.js +++ b/mcpgateway/static/admin.js @@ -5105,7 +5105,7 @@ async function handleGatewayFormSubmit(e) { const result = await response.json(); if (!result.success) { - throw new Error(result.message || "An error occurred"); + throw new Error(result?.message || "An error occurred"); } else { const redirectUrl = isInactiveCheckedBool ? `${window.ROOT_PATH}/admin?include_inactive=true#gateways` @@ -5169,7 +5169,7 @@ async function handleResourceFormSubmit(e) { const result = await response.json(); if (!result.success) { - throw new Error(result.message || "An error occurred"); + throw new Error(result?.message || "An error occurred"); } else { const redirectUrl = isInactiveCheckedBool ? `${window.ROOT_PATH}/admin?include_inactive=true#resources` @@ -5228,7 +5228,7 @@ async function handlePromptFormSubmit(e) { const result = await response.json(); if (!result.success) { - throw new Error(result.message || "An error occurred"); + throw new Error(result?.message || "An error occurred"); } // Only redirect on success const redirectUrl = isInactiveCheckedBool @@ -5283,7 +5283,7 @@ async function handleEditPromptFormSubmit(e) { const result = await response.json(); if (!result.success) { - throw new Error(result.message || "An error occurred"); + throw new Error(result?.message || "An error occurred"); } // Only redirect on success const redirectUrl = isInactiveCheckedBool @@ -5336,7 +5336,7 @@ async function handleServerFormSubmit(e) { const result = await response.json(); if (!result.success) { - throw new Error(result.message || "Failed to add server."); + throw new Error(result?.message || "Failed to add server."); } else { // Success redirect const redirectUrl = isInactiveCheckedBool @@ -5419,7 +5419,7 @@ async function handleToolFormSubmit(event) { const result = await response.json(); if (!result.success) { - throw new Error(result.message || "An error occurred"); + throw new Error(result?.message || "An error occurred"); } else { const redirectUrl = isInactiveCheckedBool ? `${window.ROOT_PATH}/admin?include_inactive=true#tools` @@ -5474,7 +5474,7 @@ async function handleEditToolFormSubmit(event) { const result = await response.json(); console.log("result edit tool form:", result); if (!result.success) { - throw new Error(result.message || "An error occurred"); + throw new Error(result?.message || "An error occurred"); } else { const redirectUrl = isInactiveCheckedBool ? `${window.ROOT_PATH}/admin?include_inactive=true#tools` @@ -5539,7 +5539,7 @@ async function handleEditGatewayFormSubmit(e) { const result = await response.json(); if (!result.success) { - throw new Error(result.message || "An error occurred"); + throw new Error(result?.message || "An error occurred"); } // Only redirect on success const redirectUrl = isInactiveCheckedBool @@ -5584,7 +5584,7 @@ async function handleEditServerFormSubmit(e) { const result = await response.json(); if (!result.success) { - throw new Error(result.message || "An error occurred"); + throw new Error(result?.message || "An error occurred"); } // Only redirect on success else { @@ -5640,7 +5640,7 @@ async function handleEditResFormSubmit(e) { const result = await response.json(); if (!result.success) { - throw new Error(result.message || "An error occurred"); + throw new Error(result?.message || "An error occurred"); } // Only redirect on success else { From 337c4fbe2df857002345bee1b267b206b73718b0 Mon Sep 17 00:00:00 2001 From: RAKHI DUTTA Date: Tue, 12 Aug 2025 12:15:28 +0530 Subject: [PATCH 2/5] admin.js Signed-off-by: RAKHI DUTTA --- mcpgateway/static/admin.js | 40 ++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/mcpgateway/static/admin.js b/mcpgateway/static/admin.js index e2b2da4da..2657cf97b 100644 --- a/mcpgateway/static/admin.js +++ b/mcpgateway/static/admin.js @@ -5104,8 +5104,8 @@ async function handleGatewayFormSubmit(e) { ); const result = await response.json(); - if (!result.success) { - throw new Error(result?.message || "An error occurred"); + if (!result || !result.success) { + throw new Error(result?.message || "Failed to add gateway"); } else { const redirectUrl = isInactiveCheckedBool ? `${window.ROOT_PATH}/admin?include_inactive=true#gateways` @@ -5168,8 +5168,8 @@ async function handleResourceFormSubmit(e) { ); const result = await response.json(); - if (!result.success) { - throw new Error(result?.message || "An error occurred"); + if (!result || !result.success) { + throw new Error(result?.message || "Failed to add Resource"); } else { const redirectUrl = isInactiveCheckedBool ? `${window.ROOT_PATH}/admin?include_inactive=true#resources` @@ -5227,8 +5227,8 @@ async function handlePromptFormSubmit(e) { ); const result = await response.json(); - if (!result.success) { - throw new Error(result?.message || "An error occurred"); + if (!result ||!result.success) { + throw new Error(result?.message || "Failed to add prompt"); } // Only redirect on success const redirectUrl = isInactiveCheckedBool @@ -5282,8 +5282,8 @@ async function handleEditPromptFormSubmit(e) { }); const result = await response.json(); - if (!result.success) { - throw new Error(result?.message || "An error occurred"); + if (!result ||!result.success) { + throw new Error(result?.message || "Failed to edit Prompt"); } // Only redirect on success const redirectUrl = isInactiveCheckedBool @@ -5335,7 +5335,7 @@ async function handleServerFormSubmit(e) { ); const result = await response.json(); - if (!result.success) { + if (!result ||!result.success) { throw new Error(result?.message || "Failed to add server."); } else { // Success redirect @@ -5418,8 +5418,8 @@ async function handleToolFormSubmit(event) { ); const result = await response.json(); - if (!result.success) { - throw new Error(result?.message || "An error occurred"); + if (!result ||!result.success) { + throw new Error(result?.message || "Failed to add tool"); } else { const redirectUrl = isInactiveCheckedBool ? `${window.ROOT_PATH}/admin?include_inactive=true#tools` @@ -5470,11 +5470,9 @@ async function handleEditToolFormSubmit(event) { body: formData, headers: { "X-Requested-With": "XMLHttpRequest" }, }); - console.log("response:", response); const result = await response.json(); - console.log("result edit tool form:", result); - if (!result.success) { - throw new Error(result?.message || "An error occurred"); + if (!result ||!result.success) { + throw new Error(result?.message || "Failed to edit tool"); } else { const redirectUrl = isInactiveCheckedBool ? `${window.ROOT_PATH}/admin?include_inactive=true#tools` @@ -5538,8 +5536,8 @@ async function handleEditGatewayFormSubmit(e) { }); const result = await response.json(); - if (!result.success) { - throw new Error(result?.message || "An error occurred"); + if (!result ||!result.success) { + throw new Error(result?.message || "Failed to edit gateway"); } // Only redirect on success const redirectUrl = isInactiveCheckedBool @@ -5583,8 +5581,8 @@ async function handleEditServerFormSubmit(e) { }); const result = await response.json(); - if (!result.success) { - throw new Error(result?.message || "An error occurred"); + if (!result ||!result.success) { + throw new Error(result?.message || "Failed to edit server"); } // Only redirect on success else { @@ -5639,8 +5637,8 @@ async function handleEditResFormSubmit(e) { }); const result = await response.json(); - if (!result.success) { - throw new Error(result?.message || "An error occurred"); + if (!result ||!result.success) { + throw new Error(result?.message || "Failed to edit resource"); } // Only redirect on success else { From 22810330fd0a561491aed4f641aec9e4a2987561 Mon Sep 17 00:00:00 2001 From: RAKHI DUTTA Date: Tue, 12 Aug 2025 13:03:19 +0530 Subject: [PATCH 3/5] admin.js Signed-off-by: RAKHI DUTTA --- mcpgateway/static/admin.js | 44 +++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/mcpgateway/static/admin.js b/mcpgateway/static/admin.js index 2657cf97b..2e49952c8 100644 --- a/mcpgateway/static/admin.js +++ b/mcpgateway/static/admin.js @@ -5102,7 +5102,11 @@ async function handleGatewayFormSubmit(e) { body: formData, }, ); - + + if (!response.ok) { + throw new Error(`HTTP ${response.status} - ${response.statusText}`); + } + const result = await response.json(); if (!result || !result.success) { throw new Error(result?.message || "Failed to add gateway"); @@ -5166,7 +5170,10 @@ async function handleResourceFormSubmit(e) { body: formData, }, ); - + + if (!response.ok) { + throw new Error(`HTTP ${response.status} - ${response.statusText}`); + } const result = await response.json(); if (!result || !result.success) { throw new Error(result?.message || "Failed to add Resource"); @@ -5226,6 +5233,9 @@ async function handlePromptFormSubmit(e) { }, ); + if (!response.ok) { + throw new Error(`HTTP ${response.status} - ${response.statusText}`); + } const result = await response.json(); if (!result ||!result.success) { throw new Error(result?.message || "Failed to add prompt"); @@ -5280,6 +5290,10 @@ async function handleEditPromptFormSubmit(e) { method: "POST", body: formData, }); + + if (!response.ok) { + throw new Error(`HTTP ${response.status} - ${response.statusText}`); + } const result = await response.json(); if (!result ||!result.success) { @@ -5334,6 +5348,10 @@ async function handleServerFormSubmit(e) { }, ); + if (!response.ok) { + throw new Error(`HTTP ${response.status} - ${response.statusText}`); + } + const result = await response.json(); if (!result ||!result.success) { throw new Error(result?.message || "Failed to add server."); @@ -5416,6 +5434,10 @@ async function handleToolFormSubmit(event) { body: formData, }, ); + + if (!response.ok) { + throw new Error(`HTTP ${response.status} - ${response.statusText}`); + } const result = await response.json(); if (!result ||!result.success) { @@ -5470,7 +5492,13 @@ async function handleEditToolFormSubmit(event) { body: formData, headers: { "X-Requested-With": "XMLHttpRequest" }, }); + + if (!response.ok) { + throw new Error(`HTTP ${response.status} - ${response.statusText}`); + } + const result = await response.json(); + if (!result ||!result.success) { throw new Error(result?.message || "Failed to edit tool"); } else { @@ -5535,6 +5563,9 @@ async function handleEditGatewayFormSubmit(e) { body: formData, }); + if (!response.ok) { + throw new Error(`HTTP ${response.status} - ${response.statusText}`); + } const result = await response.json(); if (!result ||!result.success) { throw new Error(result?.message || "Failed to edit gateway"); @@ -5579,7 +5610,10 @@ async function handleEditServerFormSubmit(e) { method: "POST", body: formData, }); - + + if (!response.ok) { + throw new Error(`HTTP ${response.status} - ${response.statusText}`); + } const result = await response.json(); if (!result ||!result.success) { throw new Error(result?.message || "Failed to edit server"); @@ -5636,6 +5670,10 @@ async function handleEditResFormSubmit(e) { body: formData, }); + if (!response.ok) { + throw new Error(`HTTP ${response.status} - ${response.statusText}`); + } + const result = await response.json(); if (!result ||!result.success) { throw new Error(result?.message || "Failed to edit resource"); From 5b9a92a23f22945e95fea81381501d5741ad903b Mon Sep 17 00:00:00 2001 From: RAKHI DUTTA Date: Tue, 12 Aug 2025 14:08:24 +0530 Subject: [PATCH 4/5] prettier Signed-off-by: RAKHI DUTTA --- mcpgateway/static/admin.js | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/mcpgateway/static/admin.js b/mcpgateway/static/admin.js index 2e49952c8..9fa98ef13 100644 --- a/mcpgateway/static/admin.js +++ b/mcpgateway/static/admin.js @@ -5102,11 +5102,9 @@ async function handleGatewayFormSubmit(e) { body: formData, }, ); - if (!response.ok) { throw new Error(`HTTP ${response.status} - ${response.statusText}`); } - const result = await response.json(); if (!result || !result.success) { throw new Error(result?.message || "Failed to add gateway"); @@ -5170,7 +5168,6 @@ async function handleResourceFormSubmit(e) { body: formData, }, ); - if (!response.ok) { throw new Error(`HTTP ${response.status} - ${response.statusText}`); } @@ -5237,7 +5234,7 @@ async function handlePromptFormSubmit(e) { throw new Error(`HTTP ${response.status} - ${response.statusText}`); } const result = await response.json(); - if (!result ||!result.success) { + if (!result || !result.success) { throw new Error(result?.message || "Failed to add prompt"); } // Only redirect on success @@ -5290,13 +5287,12 @@ async function handleEditPromptFormSubmit(e) { method: "POST", body: formData, }); - if (!response.ok) { throw new Error(`HTTP ${response.status} - ${response.statusText}`); } const result = await response.json(); - if (!result ||!result.success) { + if (!result || !result.success) { throw new Error(result?.message || "Failed to edit Prompt"); } // Only redirect on success @@ -5353,7 +5349,7 @@ async function handleServerFormSubmit(e) { } const result = await response.json(); - if (!result ||!result.success) { + if (!result || !result.success) { throw new Error(result?.message || "Failed to add server."); } else { // Success redirect @@ -5434,13 +5430,12 @@ async function handleToolFormSubmit(event) { body: formData, }, ); - if (!response.ok) { throw new Error(`HTTP ${response.status} - ${response.statusText}`); } const result = await response.json(); - if (!result ||!result.success) { + if (!result || !result.success) { throw new Error(result?.message || "Failed to add tool"); } else { const redirectUrl = isInactiveCheckedBool @@ -5498,8 +5493,7 @@ async function handleEditToolFormSubmit(event) { } const result = await response.json(); - - if (!result ||!result.success) { + if (!result || !result.success) { throw new Error(result?.message || "Failed to edit tool"); } else { const redirectUrl = isInactiveCheckedBool @@ -5562,12 +5556,11 @@ async function handleEditGatewayFormSubmit(e) { method: "POST", body: formData, }); - if (!response.ok) { throw new Error(`HTTP ${response.status} - ${response.statusText}`); } const result = await response.json(); - if (!result ||!result.success) { + if (!result || !result.success) { throw new Error(result?.message || "Failed to edit gateway"); } // Only redirect on success @@ -5610,12 +5603,12 @@ async function handleEditServerFormSubmit(e) { method: "POST", body: formData, }); - + if (!response.ok) { throw new Error(`HTTP ${response.status} - ${response.statusText}`); } const result = await response.json(); - if (!result ||!result.success) { + if (!result || !result.success) { throw new Error(result?.message || "Failed to edit server"); } // Only redirect on success @@ -5675,7 +5668,7 @@ async function handleEditResFormSubmit(e) { } const result = await response.json(); - if (!result ||!result.success) { + if (!result || !result.success) { throw new Error(result?.message || "Failed to edit resource"); } // Only redirect on success From 9463e29ab005c1918edb172fccf9738adce0f50d Mon Sep 17 00:00:00 2001 From: RAKHI DUTTA Date: Tue, 12 Aug 2025 18:12:19 +0530 Subject: [PATCH 5/5] admin.js Signed-off-by: RAKHI DUTTA --- mcpgateway/static/admin.js | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/mcpgateway/static/admin.js b/mcpgateway/static/admin.js index 9fa98ef13..7e02af471 100644 --- a/mcpgateway/static/admin.js +++ b/mcpgateway/static/admin.js @@ -5102,10 +5102,8 @@ async function handleGatewayFormSubmit(e) { body: formData, }, ); - if (!response.ok) { - throw new Error(`HTTP ${response.status} - ${response.statusText}`); - } const result = await response.json(); + if (!result || !result.success) { throw new Error(result?.message || "Failed to add gateway"); } else { @@ -5168,9 +5166,6 @@ async function handleResourceFormSubmit(e) { body: formData, }, ); - if (!response.ok) { - throw new Error(`HTTP ${response.status} - ${response.statusText}`); - } const result = await response.json(); if (!result || !result.success) { throw new Error(result?.message || "Failed to add Resource"); @@ -5229,10 +5224,6 @@ async function handlePromptFormSubmit(e) { body: formData, }, ); - - if (!response.ok) { - throw new Error(`HTTP ${response.status} - ${response.statusText}`); - } const result = await response.json(); if (!result || !result.success) { throw new Error(result?.message || "Failed to add prompt"); @@ -5287,9 +5278,6 @@ async function handleEditPromptFormSubmit(e) { method: "POST", body: formData, }); - if (!response.ok) { - throw new Error(`HTTP ${response.status} - ${response.statusText}`); - } const result = await response.json(); if (!result || !result.success) { @@ -5343,11 +5331,6 @@ async function handleServerFormSubmit(e) { redirect: "manual", }, ); - - if (!response.ok) { - throw new Error(`HTTP ${response.status} - ${response.statusText}`); - } - const result = await response.json(); if (!result || !result.success) { throw new Error(result?.message || "Failed to add server."); @@ -5430,10 +5413,6 @@ async function handleToolFormSubmit(event) { body: formData, }, ); - if (!response.ok) { - throw new Error(`HTTP ${response.status} - ${response.statusText}`); - } - const result = await response.json(); if (!result || !result.success) { throw new Error(result?.message || "Failed to add tool"); @@ -5488,10 +5467,6 @@ async function handleEditToolFormSubmit(event) { headers: { "X-Requested-With": "XMLHttpRequest" }, }); - if (!response.ok) { - throw new Error(`HTTP ${response.status} - ${response.statusText}`); - } - const result = await response.json(); if (!result || !result.success) { throw new Error(result?.message || "Failed to edit tool"); @@ -5556,9 +5531,6 @@ async function handleEditGatewayFormSubmit(e) { method: "POST", body: formData, }); - if (!response.ok) { - throw new Error(`HTTP ${response.status} - ${response.statusText}`); - } const result = await response.json(); if (!result || !result.success) { throw new Error(result?.message || "Failed to edit gateway"); @@ -5603,10 +5575,6 @@ async function handleEditServerFormSubmit(e) { method: "POST", body: formData, }); - - if (!response.ok) { - throw new Error(`HTTP ${response.status} - ${response.statusText}`); - } const result = await response.json(); if (!result || !result.success) { throw new Error(result?.message || "Failed to edit server"); @@ -5663,10 +5631,6 @@ async function handleEditResFormSubmit(e) { body: formData, }); - if (!response.ok) { - throw new Error(`HTTP ${response.status} - ${response.statusText}`); - } - const result = await response.json(); if (!result || !result.success) { throw new Error(result?.message || "Failed to edit resource");