A piece of codes:
// file defined here.
return getFile.then(function _gotFile(file) { // getFile is a promise, resolved OR rejected
// A
// do something on file
return file;
})
.catch(function() {
// B
// do other things on file,
return file;
})
In the above piece of codes, I am using promise catch
to control program flow: if getFile
promise resolved, do A
, otherwise, do B
.
Is it good practice to write codes like this?
How to rewrite the above piece of codes to avoid this? Thanks