Skip to content

Commit

Permalink
Merge pull request #13 from achambers/improve-flag-not-defined-warning
Browse files Browse the repository at this point in the history
Warn if feature flag is not defined in LD
  • Loading branch information
achambers authored Sep 26, 2017
2 parents ee7ca83 + a0c58f0 commit d2abeac
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion addon/services/launch-darkly-remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import Ember from 'ember';

import NullClient from 'ember-launch-darkly/lib/null-client';

const NON_EXISTANT_FLAG_VALUE = 'LD_FLAG_NON_EXISTANT';
const DEFAULT_FLAG_VALUE = false;

export default Service.extend({
_client: null,
_seenFlags: null,
Expand Down Expand Up @@ -63,7 +66,15 @@ export default Service.extend({
},

variation(key) {
return this.get('_client').variation(key, false);
let value = this.get('_client').variation(key, NON_EXISTANT_FLAG_VALUE);

if (value === NON_EXISTANT_FLAG_VALUE) {
warn(`Feature flag with key '${key}' has not been defined. Returning default value of '${DEFAULT_FLAG_VALUE}'`, false, { id: 'ember-launch-darkly.feature-flag-not-defined' });

return DEFAULT_FLAG_VALUE;
}

return value;
},

_config() {
Expand Down

0 comments on commit d2abeac

Please sign in to comment.