diff --git a/config.js b/config.js deleted file mode 100644 index 486302e..0000000 --- a/config.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Created by kylejohnson on 02/10/2016. - * Global config - */ -const env = process.env.config; -switch (env) { - default: { - config = require('./env/config-local'); - } -} - -module.exports = config; diff --git a/env/config-local.js b/env/config-local.js deleted file mode 100644 index 2fc9581..0000000 --- a/env/config-local.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - api : "https://api.bullet-train.io/api/v1/" -}; \ No newline at end of file diff --git a/flagsmith-core.js b/flagsmith-core.js index 8e682a2..3261e9c 100644 --- a/flagsmith-core.js +++ b/flagsmith-core.js @@ -1,5 +1,4 @@ let fetch; -const BULLET_TRAIN_KEY = "BULLET_TRAIN_DB"; const FlagsmithCore = class { @@ -28,7 +27,14 @@ const FlagsmithCore = class { options.headers['Content-Type'] = 'application/json; charset=utf-8'; } return fetch(url, options) - .then(res => res.json()); + .then(res => { + return res.json() + .then(result => { + if (res.status < 200 || res.status >= 400) { + Promise.reject(new Error(result.detail)) + } else return result; + }) + }); }; } @@ -124,19 +130,15 @@ const FlagsmithCore = class { disableCache, onError, }) { + if (!environmentID) { + throw new Error('Please specify a environment id'); + } this.environmentID = environmentID; - this.api = api; + this.api = api || "https://api.bullet-train.io/api/v1/"; this.disableCache = disableCache; this.onError = onError; - - if (!environmentID) { - throw ('Please specify a environment id'); - } - if (api === undefined) { - this.api = config.api; - } } getValue (key, userId) { diff --git a/index.js b/index.js index ffdf97a..13d7748 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,3 @@ -const config = require("./config"); const fetch = require('node-fetch').default; const core = require('./flagsmith-core'); const flagsmith = core({fetch: fetch});