I am writting a react + typescript application with Visual Studio Code:
react.js: 16.2.0 typescript: 2.6.2
I am using the built-in Promise library of vscode. But somehow I cannot propagate rejected promise to the caller function. Here I would like to simplify as much as I can my code (it is an already complex application).
Say I have an inner function Foo that returns a promise:
const Foo = (args) => {
return new Promise( (resolve, reject) => {
// 1. call a remote backend method (e.g ajax)
// 2. on call success:
resolve(success);
// 3. on call fails:
reject(error); // --> this error does not propagate
});
}
Now here is the outer function Bar that calls Foo:
const Bar = (args) => {
new Promise( (resolve, reject) => {
Foo(args).then( success => {
//...success code
}).catch(error => {
// ! this handle is never called
});
})
}
On the outer function Bar, the catch handler is never called!! It is like the inner promise rejection fails silently. I swear this was working until yesterday...I have spent half my Sunday trying to figure out was is going on.
I don't know anymore what to do. So I turn to Stackoverflow and the community. Is there anything I am missing about using Promise with Typescript? (before I was using the Q.js library. But I switched to the embedded promise library which comes with Vscode). Any help will really help me.