Skip to content

Commit 54c46df

Browse files
committed
Fix Promise.defer warnings in index.js (element-hq#7409)
Signed-off-by: Aaron Raimist <aaron@raim.ist>
1 parent a5fb33d commit 54c46df

1 file changed

Lines changed: 26 additions & 28 deletions

File tree

‎src/vector/index.js‎

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -179,37 +179,35 @@ function makeRegistrationUrl(params) {
179179
}
180180

181181
function getConfig(configJsonFilename) {
182-
let deferred = Promise.defer();
183-
184-
request(
185-
{ method: "GET", url: configJsonFilename },
186-
(err, response, body) => {
187-
if (err || response.status < 200 || response.status >= 300) {
188-
// Lack of a config isn't an error, we should
189-
// just use the defaults.
190-
// Also treat a blank config as no config, assuming
191-
// the status code is 0, because we don't get 404s
192-
// from file: URIs so this is the only way we can
193-
// not fail if the file doesn't exist when loading
194-
// from a file:// URI.
195-
if (response) {
196-
if (response.status == 404 || (response.status == 0 && body == '')) {
197-
deferred.resolve({});
182+
return new Promise(function(resolve, reject) {
183+
request(
184+
{ method: "GET", url: configJsonFilename },
185+
(err, response, body) => {
186+
if (err || response.status < 200 || response.status >= 300) {
187+
// Lack of a config isn't an error, we should
188+
// just use the defaults.
189+
// Also treat a blank config as no config, assuming
190+
// the status code is 0, because we don't get 404s
191+
// from file: URIs so this is the only way we can
192+
// not fail if the file doesn't exist when loading
193+
// from a file:// URI.
194+
if (response) {
195+
if (response.status == 404 || (response.status == 0 && body == '')) {
196+
resolve({});
197+
}
198198
}
199+
reject({err: err, response: response});
200+
return;
199201
}
200-
deferred.reject({err: err, response: response});
201-
return;
202-
}
203-
204-
// We parse the JSON ourselves rather than use the JSON
205-
// parameter, since this throws a parse error on empty
206-
// which breaks if there's no config.json and we're
207-
// loading from the filesystem (see above).
208-
deferred.resolve(JSON.parse(body));
209-
}
210-
);
211202

212-
return deferred.promise;
203+
// We parse the JSON ourselves rather than use the JSON
204+
// parameter, since this throws a parse error on empty
205+
// which breaks if there's no config.json and we're
206+
// loading from the filesystem (see above).
207+
resolve(JSON.parse(body));
208+
}
209+
);
210+
})
213211
}
214212

215213
function onTokenLoginCompleted() {

0 commit comments

Comments
 (0)