Skip to content

Commit 1067f4d

Browse files
handling duplication in catch block as per PR comments
1 parent 2b963ce commit 1067f4d

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

client/src/components/Sidebar.tsx

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ const Sidebar = ({
102102
const [copiedServerFile, setCopiedServerFile] = useState(false);
103103
const { toast } = useToast();
104104

105+
// Reusable error reporter for copy actions
106+
function reportError(error: unknown) {
107+
toast({
108+
title: "Error",
109+
description: `Failed to copy config: ${error instanceof Error ? error.message : String(error)}`,
110+
variant: "destructive",
111+
});
112+
}
113+
105114
// Shared utility function to generate server config
106115
const generateServerConfig = useCallback(() => {
107116
if (transportType === "stdio") {
@@ -159,18 +168,10 @@ const Sidebar = ({
159168
}, 2000);
160169
})
161170
.catch((error) => {
162-
toast({
163-
title: "Error",
164-
description: `Failed to copy config: ${error instanceof Error ? error.message : String(error)}`,
165-
variant: "destructive",
166-
});
171+
reportError(error);
167172
});
168173
} catch (error) {
169-
toast({
170-
title: "Error",
171-
description: `Failed to copy config: ${error instanceof Error ? error.message : String(error)}`,
172-
variant: "destructive",
173-
});
174+
reportError(error);
174175
}
175176
}, [generateMCPServerEntry, transportType, toast]);
176177

@@ -193,18 +194,10 @@ const Sidebar = ({
193194
}, 2000);
194195
})
195196
.catch((error) => {
196-
toast({
197-
title: "Error",
198-
description: `Failed to copy config: ${error instanceof Error ? error.message : String(error)}`,
199-
variant: "destructive",
200-
});
197+
reportError(error);
201198
});
202199
} catch (error) {
203-
toast({
204-
title: "Error",
205-
description: `Failed to copy config: ${error instanceof Error ? error.message : String(error)}`,
206-
variant: "destructive",
207-
});
200+
reportError(error);
208201
}
209202
}, [generateMCPServerFile, toast]);
210203

0 commit comments

Comments
 (0)