handling duplication in catch block as per PR comments
This commit is contained in:
parent
2b963ce1ce
commit
1067f4d22f
1 changed files with 13 additions and 20 deletions
|
|
@ -102,6 +102,15 @@ const Sidebar = ({
|
||||||
const [copiedServerFile, setCopiedServerFile] = useState(false);
|
const [copiedServerFile, setCopiedServerFile] = useState(false);
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
|
// Reusable error reporter for copy actions
|
||||||
|
function reportError(error: unknown) {
|
||||||
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: `Failed to copy config: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Shared utility function to generate server config
|
// Shared utility function to generate server config
|
||||||
const generateServerConfig = useCallback(() => {
|
const generateServerConfig = useCallback(() => {
|
||||||
if (transportType === "stdio") {
|
if (transportType === "stdio") {
|
||||||
|
|
@ -159,18 +168,10 @@ const Sidebar = ({
|
||||||
}, 2000);
|
}, 2000);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
toast({
|
reportError(error);
|
||||||
title: "Error",
|
|
||||||
description: `Failed to copy config: ${error instanceof Error ? error.message : String(error)}`,
|
|
||||||
variant: "destructive",
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast({
|
reportError(error);
|
||||||
title: "Error",
|
|
||||||
description: `Failed to copy config: ${error instanceof Error ? error.message : String(error)}`,
|
|
||||||
variant: "destructive",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}, [generateMCPServerEntry, transportType, toast]);
|
}, [generateMCPServerEntry, transportType, toast]);
|
||||||
|
|
||||||
|
|
@ -193,18 +194,10 @@ const Sidebar = ({
|
||||||
}, 2000);
|
}, 2000);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
toast({
|
reportError(error);
|
||||||
title: "Error",
|
|
||||||
description: `Failed to copy config: ${error instanceof Error ? error.message : String(error)}`,
|
|
||||||
variant: "destructive",
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast({
|
reportError(error);
|
||||||
title: "Error",
|
|
||||||
description: `Failed to copy config: ${error instanceof Error ? error.message : String(error)}`,
|
|
||||||
variant: "destructive",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}, [generateMCPServerFile, toast]);
|
}, [generateMCPServerFile, toast]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue