Oftentimes I want to call a promise and just let it run asynchronously instead of waiting for it. Like:
... some code ...
fetchMyCount().then(count => {
updateTheUI(count);
});
... more code ...
Now this works great, but oftentimes I don't put a failure handler on the promise because that is pretty onerous for each one. That would be like putting a try {} catch {}
on every one of my data fetches.
The problem is, if it fails, it does so silently. It doesn't throw an exception that my window.onerror
can get, it doesn't log, it doesn't do anything.
Now I can make a nice wrapper like:
Async(fetchMycount().then(count => {
updateTheUI(count);
}));
which can generically deal with promises, but then I have to remember to wrap each and every async call.
Is there a way to have a top-level handler like window.onerror
or a big try {} catch {}
wrapper that can catch all un-dealt-with rejected promises so I can log them and make sure they get fixed?