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
24 changes: 14 additions & 10 deletions frontend/src/views/ai/mcp/server/operate/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ const hasWebsite = ref(false);
const acceptParams = async (params: AI.McpServer) => {
hasWebsite.value = false;
mode.value = params.id ? 'edit' : 'create';
let mcpDomainRes;
try {
mcpDomainRes = await getMcpDomain();
if (mcpDomainRes.data.connUrl != '') {
hasWebsite.value = true;
}
} catch (error) {}

if (mode.value == 'edit') {
mcpServer.value = params;
if (!mcpServer.value.environments) {
Expand All @@ -186,16 +194,12 @@ const acceptParams = async (params: AI.McpServer) => {
if (params.port) {
mcpServer.value.port = params.port;
}
try {
const res = await getMcpDomain();
if (res.data.connUrl != '') {
const parts = res.data.connUrl.split(/(https?:\/\/)/).filter(Boolean);
mcpServer.value.protocol = parts[0];
mcpServer.value.url = parts[1];
mcpServer.value.baseUrl = res.data.connUrl;
hasWebsite.value = true;
}
} catch (error) {}
if (mcpDomainRes.data && mcpDomainRes.data.connUrl != '') {
const parts = mcpDomainRes.data.connUrl.split(/(https?:\/\/)/).filter(Boolean);
mcpServer.value.protocol = parts[0];
mcpServer.value.url = parts[1];
mcpServer.value.baseUrl = mcpDomainRes.data.connUrl;
}
}
open.value = true;
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no obvious issues with the provided code fragment, but there's a minor suggestion for improvement:

Optimizations/Suggestions

  • Avoid Unnecessary Try/Catch: The try/catch block around API calls is not strictly necessary here, especially given that we only care about handling potential errors when setting up the website URL (if available). We can simplify this by removing the catch block.

Here's the revised version of the relevant part:

const acceptParams = async (params: AI.McpServer) => {
    hasWebsite.value = false;
    mode.value = params.id ? 'edit' : 'create';
    
    try {
        const mcpDomainRes = await getMcpDomain();
        
        if (mcpDomainRes.data.connUrl != '') {
            hasWebsite.value = true;
        }
    } finally { // Ensure that the state is correctly updated regardless of success or failure
        if (hasWebsite.value) {
            let parts = mcpDomainRes.data.connUrl.split(/(https?:\/\/)/).filter(Boolean);
            mcpServer.value.protocol = parts[0];
            mcpServer.value.url = parts[1];
            mcpServer.value.baseUrl = mcpDomainRes.data.connUrl;
        }
    }

    ...
}      

If you want to explicitly handle errors without affecting the logic flow elsewhere, consider using logging instead or wrapping it in a separate error handler function that checks if the operation should be retried. However, for simpler setup workflows, the current approach should suffice.

Expand Down
Loading