Remark: It does not happen when you update the model via a non-wrapped function call, because the error is catched by the error handler mechanism of LoopBack.
See: https://github.com/joostdebruijn/loopback-date-issue
npm install.node .POST /api/Notes
[
{
"title": "Test 1",
"content": "Test",
"date": "2017-02-06"
},
{
"title": "Test 2",
"content": "Test",
"date": "2017-02-06"
}
]
POST /api/Notes/updateDatesInBulk
[
{"id": 1, "date": "thiswillfail"}
]
Receive a validation error in the callback which could be handled.
The server crashes because the error is thrown, trace:
\node_modules\loopback-datasource-juggler\lib\model-builder.js:531
throw new Error(g.f('Invalid date: %s', arg));
Error: Invalid date: thiswillfail
at DateType (node_modules\loopback-datasource-juggler\lib\model-builder.js:531:11)
at ModelConstructor.set [as startTime] (node_modules\loopback-datasource-juggler\lib\model-builder.js:467:81)
at ModelConstructor.setAttribute (node_modules\loopback-datasource-juggler\lib\dao.js:2760:14)
at ModelConstructor.setAttributes (node_modules\loopback-datasource-juggler\lib\dao.js:2793:10)
at validateAndSave (node_modules\loopback-datasource-juggler\lib\dao.js:3101:12)
at node_modules\loopback-datasource-juggler\lib\dao.js:3085:7
at doNotify (node_modules\loopback-datasource-juggler\lib\observer.js:99:49)
at doNotify (node_modules\loopback-datasource-juggler\lib\observer.js:99:49)
at doNotify (node_modules\loopback-datasource-juggler\lib\observer.js:99:49)
at doNotify (node_modules\loopback-datasource-juggler\lib\observer.js:99:49)
at Function.ObserverMixin._notifyBaseObservers (node_modules\loopback-datasource-juggler\lib\observer.js:122:5)
at Function.ObserverMixin.notifyObserversOf (node_modules\loopback-datasource-juggler\lib\observer.js:97:8)
at Function.ObserverMixin._notifyBaseObservers (node_modules\loopback-datasource-juggler\lib\observer.js:120:15)
at Function.ObserverMixin.notifyObserversOf (node_modules\loopback-datasource-juggler\lib\observer.js:97:8)
at Function.ObserverMixin._notifyBaseObservers (node_modules\loopback-datasource-juggler\lib\observer.js:120:15)
at Function.ObserverMixin.notifyObserversOf (node_modules\loopback-datasource-juggler\lib\observer.js:97:8)
Node.js: 7.5.0
loopback: 3.2.1
loopback-datasource-juggler: 3.2.0
loopback-connector-mysql: 3.0.0
This issue is also mentioned in the LoopBack-project, see https://github.com/strongloop/loopback/issues/2856, however it seems that the origin of this issue is in the datasource-juggler so I posted it here.
Confirmed. Taking this for our backlog, thanks for the report, and for the detailed reproduction.
Verified with latest code. For the example given above, it will give error code 500 and not crashing the server.
@kjdelisle @siddhipai, we had this issue verified and in to be released. Do you know why we put it back to in-progress? The PR has landed.
sorry.. close it accidentally. Reopening it.
This is fixed by https://github.com/strongloop/loopback-datasource-juggler/pull/1266