From 54088475ba6d602244479a4a4fdc43242c9ec22f Mon Sep 17 00:00:00 2001 From: Shane McDermed Date: Mon, 6 Nov 2017 15:47:49 -0700 Subject: [PATCH] Better missing param logging --- index.js | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index 9716825..1fcbffd 100644 --- a/index.js +++ b/index.js @@ -3,31 +3,27 @@ const routes = require('./factories/routes') const wares = require('./factories/wares') const Https = require('./https') +/** + * Politely tell someone they didn't define an arg + * @param {string} name + */ +function argError(name) { + throw new Error( + `You are missing some params! Make sure you set ${name} properly` + ) +} + class Sprucebot { constructor({ - apiKey, - skillId, - host, - name, - description, - skillUrl, - svgIcon, + apiKey = argError('apiKey'), + skillId = argError('apiKey'), + host = argError('apiKey'), + name = argError('apiKey'), + description = argError('apiKey'), + skillUrl = argError('apiKey'), + svgIcon = argError('apiKey'), allowSelfSignedCerts = false }) { - if ( - !apiKey || - !skillId || - !host || - !name || - !description || - !skillUrl || - !svgIcon - ) { - throw new Error( - 'You are missing some params! Make sure you pass the following: apiKey, skillId, host, name, description, skillUrl & svgIcon.' - ) - } - // Setup http(s) class with everything it needs to talk to api this.name = name this.description = description