Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions config.js

This file was deleted.

3 changes: 0 additions & 3 deletions env/config-local.js

This file was deleted.

22 changes: 12 additions & 10 deletions flagsmith-core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
let fetch;
const BULLET_TRAIN_KEY = "BULLET_TRAIN_DB";

const FlagsmithCore = class {

Expand Down Expand Up @@ -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;
})
});
};
}

Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const config = require("./config");
const fetch = require('node-fetch').default;
const core = require('./flagsmith-core');
const flagsmith = core({fetch: fetch});
Expand Down