@@ -102,6 +102,15 @@ const Sidebar = ({
102
102
const [ copiedServerFile , setCopiedServerFile ] = useState ( false ) ;
103
103
const { toast } = useToast ( ) ;
104
104
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
+
105
114
// Shared utility function to generate server config
106
115
const generateServerConfig = useCallback ( ( ) => {
107
116
if ( transportType === "stdio" ) {
@@ -159,18 +168,10 @@ const Sidebar = ({
159
168
} , 2000 ) ;
160
169
} )
161
170
. 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 ) ;
167
172
} ) ;
168
173
} 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 ) ;
174
175
}
175
176
} , [ generateMCPServerEntry , transportType , toast ] ) ;
176
177
@@ -193,18 +194,10 @@ const Sidebar = ({
193
194
} , 2000 ) ;
194
195
} )
195
196
. 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 ) ;
201
198
} ) ;
202
199
} 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 ) ;
208
201
}
209
202
} , [ generateMCPServerFile , toast ] ) ;
210
203
0 commit comments