Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 22 additions & 29 deletions mcpgateway/static/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5102,10 +5102,10 @@ async function handleGatewayFormSubmit(e) {
body: formData,
},
);

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`
Expand Down Expand Up @@ -5166,10 +5166,9 @@ async function handleResourceFormSubmit(e) {
body: formData,
},
);

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`
Expand Down Expand Up @@ -5225,10 +5224,9 @@ async function handlePromptFormSubmit(e) {
body: formData,
},
);

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
Expand Down Expand Up @@ -5282,8 +5280,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
Expand Down Expand Up @@ -5333,10 +5331,9 @@ async function handleServerFormSubmit(e) {
redirect: "manual",
},
);

const result = await response.json();
if (!result.success) {
throw new Error(result.message || "Failed to add server.");
if (!result || !result.success) {
throw new Error(result?.message || "Failed to add server.");
} else {
// Success redirect
const redirectUrl = isInactiveCheckedBool
Expand Down Expand Up @@ -5416,10 +5413,9 @@ async function handleToolFormSubmit(event) {
body: formData,
},
);

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`
Expand Down Expand Up @@ -5470,11 +5466,10 @@ 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`
Expand Down Expand Up @@ -5536,10 +5531,9 @@ async function handleEditGatewayFormSubmit(e) {
method: "POST",
body: formData,
});

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
Expand Down Expand Up @@ -5581,10 +5575,9 @@ async function handleEditServerFormSubmit(e) {
method: "POST",
body: formData,
});

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 {
Expand Down Expand Up @@ -5639,8 +5632,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 {
Expand Down
Loading