22import { values } from 'lodash' ;
33
44import type { Module , Directory } from 'common/types' ;
5+ import logError from 'app/utils/error' ;
56
67import { createAPIActions , doRequest } from '../../../api/actions' ;
78import moduleEntity from '../modules/entity' ;
@@ -391,7 +392,7 @@ const saveModuleCode = (id: string, moduleId: string) => async (
391392 dispatch ( moduleActions . setCode ( newModule . id , module . code ) ) ;
392393
393394 try {
394- await dispatch (
395+ const { data } = await dispatch (
395396 doRequest (
396397 SAVE_MODULE_CODE_API_ACTIONS ,
397398 `sandboxes/${ sandboxId } /modules/${ module . shortid } ` ,
@@ -401,14 +402,33 @@ const saveModuleCode = (id: string, moduleId: string) => async (
401402 } ,
402403 ) ,
403404 ) ;
404- dispatch ( moduleActions . setModuleSynced ( newModule . id ) ) ;
405+
406+ if ( data . code !== newModule . code ) {
407+ dispatch (
408+ notificationActions . addNotification (
409+ 'Something went wrong while saving the module, please try again.' ,
410+ 'error' ,
411+ ) ,
412+ ) ;
413+
414+ logError (
415+ new Error (
416+ `Saving module went wrong, mismatch:\n\n${ data . code } \n\nvs\n\n ${ newModule . code } ` ,
417+ ) ,
418+ ) ;
419+ } else {
420+ dispatch ( moduleActions . setModuleSynced ( newModule . id ) ) ;
421+ }
422+ return data ;
405423 } catch ( e ) {
406424 dispatch (
407425 notificationActions . addNotification (
408426 'Could not save the module, please try again.' ,
409427 'error' ,
410428 ) ,
411429 ) ;
430+ e . message = `Could not save module: ${ e . message } ` ;
431+ logError ( e ) ;
412432 }
413433} ;
414434/**
@@ -439,7 +459,7 @@ const massUpdateModules = (id: string) => async (
439459 } ,
440460 ) ,
441461 ) ;
442-
462+ // TODO validate return values from server
443463 modulesNotInSyncInSandbox . forEach ( m =>
444464 dispatch ( moduleActions . setModuleSynced ( m . id ) ) ,
445465 ) ;
0 commit comments