1
I am trying to treat a timeout error. When the timeout occurs the application should run again. Initially this loop should be done in an external module that calls this, however due to the difficulties I ended up trying to treat both in the same file.
Currently the code is as follows:
exports.acesso = function(sitepage, selector) {
//variaveis
const now = new Date,
fs = require('fs'),
Nightmare = require('nightmare'),
nightmare = Nightmare({
show: false,
waitTimeout: 2
});
var date, result = {};
//processo
var processo = function() {
nightmare.goto(sitepage)
.wait(selector)
.evaluate(function(selector) {
return document.querySelector(selector).innerText;
})
.end()
.then(function(result) {
console.log(result);
})
.catch(function(error) {
if (error.message === '.wait() timed out after 2msec') {
console.error('Error: 500');
console.log('tentando novamente');
//aqui deveria ocorrer o loop
//tentei com processo();
} else {
console.error(error);
return error;
}
})
}
processo();
}
There was some mistake when you used
processo();
within thecatch
?– Sergio
No, it closes the application, but does not loop
– Victor Apolonio
Maybe Promise chaining is failing... Take a look here: https://jsfiddle.net/c8rsddrf/, adapting to your case you would have to do
return nightmare.goto(sitepage) ... etc
and then inside thecatch
when you call again the process doreturn processo();
. Test that.– Sergio