Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var url = baseUrl + '/' + encodeURIComponent(methodName) + '/' + encodeURIComponent(JSON.stringify(args));
// Deprecated
// if (username && hashedPassword) {
// url += '?username=' + encodeURIComponent(username) + '&hashedPassword=' + encodeURIComponent(hashedPassword);
// }
//log("url=", url);
var headers = {
'Exp-ClientId': await session.clientIdAsync(),
};
if (username) {
headers['Exp-Username'] = username;
}
var response = await needle.promise.post(url, null, {headers});
var ro = response.body;
// try {
// var response = JSON.parse(body);
// } catch (e) {
// var err = new Error("Unparseable response from API server: " + body);
// throw err;
// }
if (ro.err) {
throw ApiError(ro.code, ro.err.env, ro.err);
}
return ro;
};
var url = baseUrl + '/' + encodeURIComponent(methodName) + '/' + encodeURIComponent(JSON.stringify(args));
// Deprecated
// if (username && hashedPassword) {
// url += '?username=' + encodeURIComponent(username) + '&hashedPassword=' + encodeURIComponent(hashedPassword);
// }
//log("url=", url);
var headers = {};
if (username) {
headers = {
'Exp-ClientId': yield session.clientIdAsync(),
'Exp-Username': username };
}
var response = yield needle.promise.post(url, null, { headers: headers });
var ro = response.body;
// try {
// var response = JSON.parse(body);
// } catch (e) {
// var err = new Error("Unparseable response from API server: " + body);
// throw err;
// }
if (ro.err) {
throw ApiError(ro.code, ro.err.env, ro.err);
}
return ro;
});
var outStream = process.stdout;
if (filepath) {
outStream = fs.createWriteStream(filepath);
}
var url = await urlUtil.mainBundleUrlAsync(uo);
log("Requesting bundle from", url, "...");
if (filepath) {
log("Saving to", filepath);
}
try {
simpleSpinner.start();
try {
var response = await needle.promise.get(url);
} catch (e) {
throw CommandError('NO_RESPONSE', env, "Server didn't respond.\n" + e.message);
} finally {
simpleSpinner.stop();
}
if (response.statusCode != 200) {
if (_.isObject(response.body)) {
var errInfo = response.body;
log.error(errInfo.type, errInfo.message);
console.error(errInfo.snippet);
if (errInfo.type) {
throw CommandError(errInfo.type, env, "Error in generating bundle");
}
} else {
log.error("Uknown Error:", response.body);
var outStream = process.stdout;
if (filepath) {
outStream = fs.createWriteStream(filepath);
}
var url = yield urlUtil.mainBundleUrlAsync(uo);
log('Requesting bundle from', url, '...');
if (filepath) {
log('Saving to', filepath);
}
try {
simpleSpinner.start();
try {
var response = yield needle.promise.get(url);
} catch (e) {
throw CommandError('NO_RESPONSE', env, 'Server didn\'t respond.\n' + e.message);
} finally {
simpleSpinner.stop();
}
if (response.statusCode != 200) {
throw CommandError('BAD_RESPONSE', env, 'Non-200 response: ' + response.statusCode + ': ' + response.statusMessage);
}
} catch (e) {
throw CommandError('FAILED_TO_DOWNLOAD_BUNDLE', env, 'Failed to download bundle; did you run `exp start`?\n' + e);
}
yield outStream.promise.write(response.body);
var bytes = response.body.length;
if (filepath) {
async function testUrlAsync(url) {
var httpUrl = url.replace(/^exp:\/\//, 'http://');
var response = await needle.promise.get(httpUrl);
if (!(response.statusCode == 200)) {
throw new Error("Problem reading from URL " + httpUrl + "\nstatusCode=" + response.statusCode);
}
return url;
}