diff --git a/server/src/lib/ciscoController.js b/server/src/lib/ciscoController.js index 51157d7..b933069 100644 --- a/server/src/lib/ciscoController.js +++ b/server/src/lib/ciscoController.js @@ -6,30 +6,34 @@ import { logError } from './logger' const TIMEOUT_IN_MS = 120000 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) => `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, + 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 timeout = setTimeout(() => { 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) let skip = 0