Binato/server/util/AsyncHttpRequest.js

16 lines
434 B
JavaScript
Raw Normal View History

const request = require("request"), RequestType = require("./RequestType.json");
2021-02-13 13:01:40 +00:00
const functionMap = {
0: (resolve, body) => resolve(body),
1: (resolve, body) => resolve(JSON.parse(body)),
2: null
};
module.exports = async function(url, reqType = RequestType.Text) {
return new Promise((resolve, reject) => {
request(url, (err, res, body) => {
if (err) reject(err);
else functionMap[reqType](resolve, body);
});
});
2021-02-13 13:01:40 +00:00
}