Move axios inside promise
This commit is contained in:
parent
2d663de5cf
commit
ea50630ea1
|
@ -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({
|
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`
|
||||||
|
|
||||||
|
function getDevices() {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
const httpsAgent = new https.Agent({
|
||||||
rejectUnauthorized: false,
|
rejectUnauthorized: false,
|
||||||
ciphers: 'AES256-SHA' // That's necessary to connect to a TLS 1.0 server. Run node with --tls-min-v1.0
|
ciphers: 'AES256-SHA' // That's necessary to connect to a TLS 1.0 server. Run node with --tls-min-v1.0
|
||||||
})
|
})
|
||||||
|
|
||||||
const axios = create({
|
const axios = create({
|
||||||
httpsAgent: httpsAgent,
|
httpsAgent: httpsAgent,
|
||||||
timeout: REQUEST_TIMEOUT_IN_MS,
|
timeout: REQUEST_TIMEOUT_IN_MS,
|
||||||
auth: {
|
auth: {
|
||||||
username: process.env.CISCO_USER,
|
username: process.env.CISCO_USER,
|
||||||
password: process.env.CISCO_PASSWORD
|
password: process.env.CISCO_PASSWORD
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
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`
|
|
||||||
|
|
||||||
function getDevices() {
|
|
||||||
return new Promise(async (resolve, reject) => {
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user