Skip to content

Commit cb516de

Browse files
committed
Enhance error msg for unsupported types
1 parent 7aee03e commit cb516de

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/server/router/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,24 @@ module.exports = function (source) {
5757

5858
// Create routes
5959
for (var prop in db.object) {
60-
if (_.isPlainObject(db.object[prop])) {
60+
var val = db.object[prop]
61+
62+
if (_.isPlainObject(val)) {
6163
router.use('/' + prop, singular(db, prop))
6264
continue
6365
}
6466

65-
if (_.isArray(db.object[prop])) {
67+
if (_.isArray(val)) {
6668
router.use('/' + prop, plural(db, prop))
6769
continue
6870
}
6971

70-
throw new Error('Unsupported type')
72+
var msg =
73+
'Type of "' + prop + '" (' + typeof val + ') ' +
74+
(_.isObject(source) ? '' : 'in ' + source) + ' is not supported. ' +
75+
'Use objects or arrays of objects.'
7176

77+
throw new Error(msg)
7278
}
7379

7480
router.use(function (req, res) {

0 commit comments

Comments
 (0)