-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prevent /config call on multiple initializations #188
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,10 @@ class Radar { | |
throw new RadarPublishableKeyError('Secret keys are not allowed. Please use your Radar publishable key.'); | ||
} | ||
|
||
if (Config.isInitialized()) { | ||
Logger.error('Radar.initialize() called more than once.'); | ||
} | ||
|
||
// store settings in global config | ||
const live = isLiveKey(publishableKey); | ||
const logLevel = live ? 'error' : 'info'; | ||
|
@@ -79,11 +83,15 @@ class Radar { | |
Logger.debug('using options', options); | ||
} | ||
|
||
// NOTE(jasonl): this allows us to run jest tests | ||
// without having to mock the ConfigAPI.getConfig call | ||
if (!(window as any)?.RADAR_TEST_ENV) { | ||
ConfigAPI.getConfig(); | ||
if (!Config.isInitialized()) { // only call getConfig on first initialization | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we want to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that's the one scenario I was sort of thinking of. Maybe it's worth just checking if the config options have changed or not. |
||
// NOTE(jasonl): this allows us to run jest tests | ||
// without having to mock the ConfigAPI.getConfig call | ||
if (!(window as any)?.RADAR_TEST_ENV) { | ||
ConfigAPI.getConfig(); | ||
} | ||
} | ||
|
||
Config.setInitialized(); | ||
} | ||
|
||
public static clear() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we're handling this, should we
Logger.warn
instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it's a "warn" and not an error, but I also sort of want this to fire on a production site. Maybe I will just change to
console.warn
instead of using the Logger class.