I am seeking an understanding of the below code - specifically what happens when the following code of returning string from inside catch block is encountered i.e. return 'Promise Error caught'
.
function job(state) {
return new Promise(function(resolve, reject) {
if (state) {
resolve('Promise success');
} else {
reject('Promise error');
}
});
}
let promise = job(true);
promise.then(function(data) {
console.log(data);
return job(false);
}).catch(function(error) {
console.log(error);
return 'Promise Error caught';
}).then(function(data) {
console.log(data);
return job(true);
}).catch(function(error) {
console.log(error);
});