I recently found myself in a situation very difficult to debug. Imagine the following very simple situation:
function somePromise() {
return new Promise((resolve, reject) => {
SomeModule.someMethod();
AnotherModule.somePromise().then(resolve).catch(reject);
});
}
Resolve was never called, but I didn't get an error in the console - this was difficult to debug!
Turns out that I forgot to require SomeModule
. After requiring it, the code worked as expected.
Is there a way to automatically try/catch every Promise in my code with an error handler? I don't want to surround the body of my Promises with a try/catch block just to be able to find such errors more easily in the future.
Thanks in advance for opinions!