File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -190,24 +190,29 @@ module.exports = function (argv) {
190190 // Since lowdb uses atomic writing, directory is watched instead of file
191191 const watchedDir = path . dirname ( source )
192192 fs . watch ( watchedDir , ( event , file ) => {
193+ < << << << HEAD
193194 // https://github.com/typicode/json-server/issues/420
194195 // file can be null
195196 if ( file ) {
196197 const watchedFile = path . resolve ( watchedDir , file )
197198 if ( watchedFile === path . resolve ( source ) ) {
198199 if ( is . JSON ( watchedFile ) ) {
199- var obj = JSON . parse ( fs . readFileSync ( watchedFile ) )
200+ var obj
201+ try {
202+ obj = JSON . parse ( fs . readFileSync ( watchedFile ) )
203+ } catch ( e ) {
204+ console . log ( 'Error reading JSON file' ) ;
205+ console . dir ( e ) ;
206+ return ;
207+ }
208+
200209 // Compare .json file content with in memory database
201210 var isDatabaseDifferent = ! _ . isEqual ( obj , app . db . getState ( ) )
202211 if ( isDatabaseDifferent ) {
203212 console . log ( chalk . gray ( ` ${ source } has changed, reloading...` ) )
204213 server && server . destroy ( )
205214 start ( )
206215 }
207- } else {
208- console . log ( chalk . gray ( ` ${ source } has changed, reloading...` ) )
209- server && server . destroy ( )
210- start ( )
211216 }
212217 }
213218 }
You can’t perform that action at this time.
0 commit comments