File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -358,11 +358,18 @@ export const storeCustomGame = async (data: {
358358 body : JSON . stringify ( data ) ,
359359 } )
360360
361+ const bodyText = await res . text ( )
362+
361363 if ( ! res . ok ) {
362- console . error ( `Failed to store custom game: ${ await res . text ( ) } ` )
364+ console . error ( `Failed to store custom game: ${ bodyText } ` )
365+ throw new Error (
366+ `Failed to store custom game (${ res . status } ${ res . statusText } )${
367+ bodyText ? `: ${ bodyText } ` : ''
368+ } `,
369+ )
363370 }
364371
365- return res . json ( )
372+ return JSON . parse ( bodyText )
366373}
367374
368375export const deleteCustomGame = async ( gameId : string ) : Promise < void > => {
Original file line number Diff line number Diff line change @@ -347,14 +347,23 @@ const Analysis: React.FC<Props> = ({
347347 const handleCustomAnalysis = useCallback (
348348 ( type : 'fen' | 'pgn' , data : string , name ?: string ) => {
349349 ; ( async ( ) => {
350- const { game_id } = await storeCustomGame ( {
351- name : name ,
352- pgn : type === 'pgn' ? data : undefined ,
353- fen : type === 'fen' ? data : undefined ,
354- } )
355-
356- setShowCustomModal ( false )
357- router . push ( `/analysis/${ game_id } /custom` )
350+ try {
351+ const { game_id } = await storeCustomGame ( {
352+ name : name ,
353+ pgn : type === 'pgn' ? data : undefined ,
354+ fen : type === 'fen' ? data : undefined ,
355+ } )
356+
357+ setShowCustomModal ( false )
358+ router . push ( `/analysis/${ game_id } /custom` )
359+ } catch ( error ) {
360+ const message =
361+ error instanceof Error
362+ ? error . message
363+ : 'Failed to store custom game'
364+ console . error ( 'Custom analysis import failed:' , error )
365+ toast . error ( message )
366+ }
358367 } ) ( )
359368 } ,
360369 [ ] ,
You can’t perform that action at this time.
0 commit comments