Enhance error msg for unsupported types

This commit is contained in:
Typicode
2015-08-04 04:37:19 +02:00
parent 7aee03ecf5
commit cb516def96

View File

@ -57,18 +57,24 @@ module.exports = function (source) {
// Create routes // Create routes
for (var prop in db.object) { for (var prop in db.object) {
if (_.isPlainObject(db.object[prop])) { var val = db.object[prop]
if (_.isPlainObject(val)) {
router.use('/' + prop, singular(db, prop)) router.use('/' + prop, singular(db, prop))
continue continue
} }
if (_.isArray(db.object[prop])) { if (_.isArray(val)) {
router.use('/' + prop, plural(db, prop)) router.use('/' + prop, plural(db, prop))
continue continue
} }
throw new Error('Unsupported type') var msg =
'Type of "' + prop + '" (' + typeof val + ') ' +
(_.isObject(source) ? '' : 'in ' + source) + ' is not supported. ' +
'Use objects or arrays of objects.'
throw new Error(msg)
} }
router.use(function (req, res) { router.use(function (req, res) {