From a5fb33de026711b0e5795f19b26999f83a827291 Mon Sep 17 00:00:00 2001 From: Aaron Raimist Date: Tue, 2 Oct 2018 19:20:03 -0500 Subject: [PATCH] Fix Promise.defer warnings in getconfig.js (#7409) Signed-off-by: Aaron Raimist --- src/vector/getconfig.js | 54 ++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/vector/getconfig.js b/src/vector/getconfig.js index f3e7bea16..868840c6a 100644 --- a/src/vector/getconfig.js +++ b/src/vector/getconfig.js @@ -33,35 +33,33 @@ export async function getVectorConfig(relativeLocation) { } function getConfig(configJsonFilename) { - let deferred = Promise.defer(); - - request( - { method: "GET", url: configJsonFilename }, - (err, response, body) => { - if (err || response.status < 200 || response.status >= 300) { - // Lack of a config isn't an error, we should - // just use the defaults. - // Also treat a blank config as no config, assuming - // the status code is 0, because we don't get 404s - // from file: URIs so this is the only way we can - // not fail if the file doesn't exist when loading - // from a file:// URI. - if (response) { - if (response.status == 404 || (response.status == 0 && body == '')) { - deferred.resolve({}); + return new Promise(function(resolve, reject) { + request( + { method: "GET", url: configJsonFilename }, + (err, response, body) => { + if (err || response.status < 200 || response.status >= 300) { + // Lack of a config isn't an error, we should + // just use the defaults. + // Also treat a blank config as no config, assuming + // the status code is 0, because we don't get 404s + // from file: URIs so this is the only way we can + // not fail if the file doesn't exist when loading + // from a file:// URI. + if (response) { + if (response.status == 404 || (response.status == 0 && body == '')) { + resolve({}); + } } + reject({err: err, response: response}); + return; } - deferred.reject({err: err, response: response}); - return; + + // We parse the JSON ourselves rather than use the JSON + // parameter, since this throws a parse error on empty + // which breaks if there's no config.json and we're + // loading from the filesystem (see above). + resolve(JSON.parse(body)); } - - // We parse the JSON ourselves rather than use the JSON - // parameter, since this throws a parse error on empty - // which breaks if there's no config.json and we're - // loading from the filesystem (see above). - deferred.resolve(JSON.parse(body)); - } - ); - - return deferred.promise; + ); + }) }