Skip to content

Commit

Permalink
Fix Promise.defer warnings in index.js (element-hq#7409)
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Raimist <aaron@raim.ist>
  • Loading branch information
aaronraimist committed Oct 5, 2018
1 parent a5fb33d commit 54c46df
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions src/vector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,37 +179,35 @@ function makeRegistrationUrl(params) {
}

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).
deferred.resolve(JSON.parse(body));
}
);

return deferred.promise;
// 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));
}
);
})
}

function onTokenLoginCompleted() {
Expand Down

0 comments on commit 54c46df

Please sign in to comment.