File tree 1 file changed +10
-5
lines changed
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) {
190
190
// Since lowdb uses atomic writing, directory is watched instead of file
191
191
const watchedDir = path . dirname ( source )
192
192
fs . watch ( watchedDir , ( event , file ) => {
193
+ < << << << HEAD
193
194
// https://github.com/typicode/json-server/issues/420
194
195
// file can be null
195
196
if ( file ) {
196
197
const watchedFile = path . resolve ( watchedDir , file )
197
198
if ( watchedFile === path . resolve ( source ) ) {
198
199
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
+
200
209
// Compare .json file content with in memory database
201
210
var isDatabaseDifferent = ! _ . isEqual ( obj , app . db . getState ( ) )
202
211
if ( isDatabaseDifferent ) {
203
212
console . log ( chalk . gray ( ` ${ source } has changed, reloading...` ) )
204
213
server && server . destroy ( )
205
214
start ( )
206
215
}
207
- } else {
208
- console . log ( chalk . gray ( ` ${ source } has changed, reloading...` ) )
209
- server && server . destroy ( )
210
- start ( )
211
216
}
212
217
}
213
218
}
You can’t perform that action at this time.
0 commit comments