Skip to content

Commit 383172b

Browse files
don't send env option if it's not passed
1 parent 339a76b commit 383172b

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

lib/api.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ module.exports.lastApiError = lastApiError;
1313
module.exports.methods = {
1414

1515
identifyApp: function identifyApp(settings) {
16-
var appname = helpers.getAppName(),
16+
var options = {},
17+
appname = helpers.getAppName(),
1718
body = {
1819
DeviceName: os.hostname(),
1920
AppName: appname,
2021
ConfiguredAppName: appname,
21-
AppLocaton: process.env.PWD,
22-
ConfiguredEnvName: settings && settings.env ? settings.env : (process.env.NODE_ENV || null)
22+
AppLocaton: process.env.PWD
2323
},
24-
opt = helpers.getOptions(CONFIG.IDENTIFY_PATH, body, settings ? settings.proxy : undefined),
2524
callback = function (data) {
2625
debug.write('Successfully identified');
2726

@@ -37,7 +36,7 @@ module.exports.methods = {
3736
fail = function () {
3837
debug.write('Identification failed');
3938
setTimeout(function () {
40-
sender.send(opt, callback, fail);
39+
sender.send(options, callback, fail);
4140
}, CONFIG.IDENTIFY_DELAY);
4241
};
4342

@@ -50,10 +49,17 @@ module.exports.methods = {
5049

5150
if (settings.apiKey && typeof (settings.apiKey) === 'string') {
5251
CONFIG.APIKEY = settings.apiKey;
53-
opt.headers['X-Stackify-Key'] = settings.apiKey;
5452
CONFIG.APPNAME = appname;
53+
54+
if (settings.env) {
55+
body.ConfiguredEnvName = settings.env;
56+
}
57+
58+
options = helpers.getOptions(CONFIG.IDENTIFY_PATH, body, settings ? settings.proxy : undefined);
59+
options.headers['X-Stackify-Key'] = settings.apiKey;
60+
5561
debug.write('Identifying the app');
56-
sender.send(opt, callback, fail);
62+
sender.send(options, callback, fail);
5763
} else {
5864
debug.write('You have to pass API key to initialize Stackify Logger');
5965
throw new TypeError('You have to pass API key');
@@ -69,7 +75,7 @@ module.exports.methods = {
6975
*/
7076
postLogs: function postLogs(messages, cb, shutdown) {
7177
var delay = 0, // scheduled delay when postLogs call failed
72-
opt = helpers.getOptions(CONFIG.LOG_SAVE_PATH, helpers.getPostBody(messages), CONFIG.PROXY),
78+
options = helpers.getOptions(CONFIG.LOG_SAVE_PATH, helpers.getPostBody(messages), CONFIG.PROXY),
7379

7480
//retry the request if it failed
7581
fail = function (code) {
@@ -85,11 +91,11 @@ module.exports.methods = {
8591
}
8692

8793
setTimeout(function () {
88-
sender.send(opt, cb, fail);
94+
sender.send(options, cb, fail);
8995
}, delay);
9096
};
9197
debug.write('Sending logs: batch size: ' + messages.length + ' messages');
92-
sender.send(opt, cb, shutdown ? null : fail);
98+
sender.send(options, cb, shutdown ? null : fail);
9399
},
94100
/*
95101
*** posting logs synchronously in case if server is about to close ***

0 commit comments

Comments
 (0)