From cb516def969843611f72765cce01bc947593fdfe Mon Sep 17 00:00:00 2001 From: Typicode Date: Tue, 4 Aug 2015 04:37:19 +0200 Subject: [PATCH] Enhance error msg for unsupported types --- src/server/router/index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/server/router/index.js b/src/server/router/index.js index ccdd274..31031ac 100644 --- a/src/server/router/index.js +++ b/src/server/router/index.js @@ -57,18 +57,24 @@ module.exports = function (source) { // Create routes 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)) continue } - if (_.isArray(db.object[prop])) { + if (_.isArray(val)) { router.use('/' + prop, plural(db, prop)) 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) {