-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (31 loc) · 856 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const axios = require('axios')
const constants = require('./text.js')
const helpers = require('./helpers.js')
const R = require('ramda')
class httpRequest {
/**
* ability to get requests and return contents to url
* @param {*} urls
*/
requestUrls(urls) {
// validation checking of urls are valid
if (!urls) {
throw new Error(constants.errorMessage.notValidUrls)
}
if (!helpers.validateUrls(urls)) {
throw new Error(constants.errorMessage.notValidUrls)
}
return Promise.all(
urls.map(async (url) => {
return axios({ url: url })
}),
).catch((error) => {
return {
...error,
message: R.pathOr('', ['message'], error),
statusCode: R.pathOr(400, ['response', 'status'], error), // return 400 client issue
}
})
}
}
module.exports = httpRequest