Move axios inside promise

This commit is contained in:
Douglas Barone 2021-11-16 08:00:49 -04:00
parent 2d663de5cf
commit ea50630ea1

View File

@ -6,30 +6,34 @@ import { logError } from './logger'
const TIMEOUT_IN_MS = 120000 const TIMEOUT_IN_MS = 120000
const REQUEST_TIMEOUT_IN_MS = 20000 const REQUEST_TIMEOUT_IN_MS = 20000
const httpsAgent = new https.Agent({
rejectUnauthorized: false,
ciphers: 'AES256-SHA' // That's necessary to connect to a TLS 1.0 server. Run node with --tls-min-v1.0
})
const axios = create({
httpsAgent: httpsAgent,
timeout: REQUEST_TIMEOUT_IN_MS,
auth: {
username: process.env.CISCO_USER,
password: process.env.CISCO_PASSWORD
}
})
const getUri = (skip, page, take) => const getUri = (skip, page, take) =>
`https://${process.env.CISCO_HOST}/data/client-table.html?columns=524287&take=${take}&skip=${skip}&page=${page}&pageSize=50&sort[0][field]=ST&sort[0][dir]=desc` `https://${process.env.CISCO_HOST}/data/client-table.html?columns=524287&take=${take}&skip=${skip}&page=${page}&pageSize=50&sort[0][field]=ST&sort[0][dir]=desc`
function getDevices() { function getDevices() {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
const httpsAgent = new https.Agent({
rejectUnauthorized: false,
ciphers: 'AES256-SHA' // That's necessary to connect to a TLS 1.0 server. Run node with --tls-min-v1.0
})
const axios = create({
httpsAgent: httpsAgent,
timeout: REQUEST_TIMEOUT_IN_MS,
auth: {
username: process.env.CISCO_USER,
password: process.env.CISCO_PASSWORD
}
})
const source = CancelToken.source() const source = CancelToken.source()
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
source.cancel('timeout') source.cancel('timeout')
reject(new Error('A operação getDevices foi cancelada pelo tempo limite')) reject(
new Error(
'A operação getDevices foi cancelada pois atingiu o tempo limite'
)
)
}, TIMEOUT_IN_MS) }, TIMEOUT_IN_MS)
let skip = 0 let skip = 0